路政项目中用法
<%
Organinfo organinfo= (Organinfo)session.getAttribute("organinfo");
organinfo.getOid();
%>
<html:select property="o!cersinfo.oname" style="width:150px">
<html:optionsCollection name="onamelist" label="oname" value="oid"/>
</html:select>
<html:select>标签的用法
<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 把它的内容写出来了