首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

html:select的取值有关问题

2012-03-28 
html:select的取值问题我用的struts架构jsp页面中:html:selectproperty interesting multiple true

html:select的取值问题
我用的struts架构
jsp页面中:
<html:select   property= "interesting "     multiple= "true ">
<html:option   value= "htmlselect.sing "> Sing </html:option>
<html:option   value= "htmlselect.print "> Print </html:option>
<html:option   value= "htmlselect.film "> Film </html:option>
<html:option   value= "htmlselect.computerGame "> Computer   Game </html:option>
<html:option   value= "htmlselect.other "> Other </html:option>
</html:select>
可以多选,对应的form中,我定义了一个与之对应的数组,可以自动获得值,问题是
自动获得的是我选中的value值,如:htmlselect.print,而我想要的是显示的文本值,如何得到呢。不能把value和显示文本写成一样的。
高手指点一下,分不多了,多谢。

[解决办法]
html:select获得的只能是value
[解决办法]
同意楼上的,只能取value,把文本值写到资源文件,通过key来取得
[解决办法]
首先用了struts的tag问题变得很简单了

<html:select size= "1 " styleClass= "scrolltext " name= "FolderManagerForm " property= "avaiableFolder " style= "width=100% " onchange= "parentChange();return false; ">
<html:options name= "FolderManagerForm " labelProperty= "dropFolderNameList " property= "dropFolderList " />
</html:select>

这个就是标准的struts的实现方式
<html:select 中:
name= "FolderManagerForm " 你的form的名字
property= "avaiableFolder " 你改为“interesting”

<html:options 中:
name= "FolderManagerForm " 你的form的名字
labelProperty= "dropFolderNameList "
property= "dropFolderList "

property,labelProperty 分别对应你下拉列表的List值。

property 在form中是一个ArrayList。用来表示code
labelProperty 在form中是一个ArrayList。用来表示名称
比如问题中
value= "htmlselect.sing "> Sing </html:option>
<html:option value= "htmlselect.print "> Print </html:option>
<html:option value= "htmlselect.film "> Film </html:option>
<html:option value= "htmlselect.computerGame "> Computer Game </html:option>
<html:option value= "htmlselect.other "> Other </html:option>

可以把Sing,Print。。。。。 放到一个ArrayList中,然后通过 labelProperty 表示出来



[解决办法]
<body>
<form>
<select name= "select1 ">
<option value= "v1 "> l1 </option>
<option value= "v2 "> l2 </option>
</select>
<input type= "hidden " name= "hide1 ">
<input type= "submit " onclick= "document.all[ 'hide1 '].value=document.all[ 'select1 '].options[document.all[ 'select1 '].selectedIndex].text; ">
</form>
</body>
[解决办法]
我觉的可以变通一下 改为
jsp页面中:
<html:select property= "interesting " multiple= "true ">
<html:option value= "htmlselect.sing$Sing "> Sing </html:option>
<html:option value= "htmlselect.print$Print "> Print </html:option>
<html:option value= "htmlselect.film$Film "> Film </html:option>
<html:option value= "htmlselect.computerGame$Computer Game "> Computer Game </html:option>


<html:option value= "htmlselect.other$Other "> Other </html:option>
</html:select>
然后根据传进的值是否indexOf(数组[i]) != -1 ,那么split( '$ ')后的数组[1]就是得到的值了
[解决办法]
ArrayList arrayList = new ArrayList();

arrayList.add(new LabelValueBean( "1001 ", "name1 "));
arrayList.add(new LabelValueBean( "1002 ", "name2 "));
arrayList.add(new LabelValueBean( "1003 ", "name3 "));

request.setAttribute( "list ",arrayList);
可以在Action里实现.


<html:select property= "username ">
<html:options collection= "list " property= "id " labelProperty= "name " />
</html:select/>

[解决办法]
dreamover(梦醒了〖http://hellfire.cn〗)
_____________________________________
正解

热点排行