<html:select property="theChoice">
<html:options collection="choiceLists" property="value" labelProperty="description" />
</html:select>
//theChoice是beanForm的成员 choiceLists可以是一个 List 类型的bean
意思就是dropdown list的全部内容,来自一个叫“choiceLists”的collection,对这个collection里的每个成员进行getValue()和getDescription(),即得到dropdown list每个item的value和text。这个dropdown list中谁被选中,决定于你的bean的getTheChoice()返回的值和这个Collection中哪个成员的getValue()相等。
好像这算是一种用法,别的还有好多别的用法,看看这里吧:
http://struts.apache.org/userGuide/struts-html.html
select标签的用法比较复杂,什么name,property,labelname,labelproperty,id这些属性用得乱七八糟
我是这样实现的
<html:select property="customer_id">
<logic:iterate name="customer" id="cusbean">
<option value='<bean:write name="cusbean" property="value"/>'>
<bean:write name="cusbean" property="label"/>
</option>
</logic:iterate>
</html:select>
第一行的customer_id 是 ActionForm里定义的变量
第二行的customer是一个collection,存放的是一个自定义的bean,bean里只有两个属性(label和value),在action中从数据库读入客户信息,写入自定义的bean,在将bean放入collection,最后再写入request(request.setAttribute("customer",mybean);),cusbean是id名字可以随便取,它将request中的customer转换成jsp page scope 的bean,第三、第四行就可以用bean:write把它的内容写出来了
<html:select property="atprovince">
<html:optionsCollection name="PreAddagentActionForm" property="provinceList" label="provincename" value="provinceid"/>
使用html:optionsCollection 就可以了。
我做的一个项目,销售
<html:select property="username" name="userlistForm">
<logic:iterate id="dept" name="depts">
<html:option value="1">
<bean:write name="dept" property="name"/>
</html:option>
</logic:iterate>
</html:select>