使用Collection来给html:options 标签的collection属性赋值
<html:select property="userId">
<html:option value="">all</html:option>
<html:options collection="${userlist}" property="userID"
labelProperty="userName" />
</html:select>
userlist 通过以下语句赋值
<c:set var="userlist" value="${springctx.userAccountService.userAccounts}"/>
userlist为一存放有UserAccount对象的list。userID,userName为UserAccount对象的属性。
property="userID" 指 以collection指定的对象里每个元素的userID做为options 的property。
labelProperty="userName" 指collection指定的对象里每个元素的userName做为options 的labelProperty。
------------------------------------------------------
使用Map来为html:options 标签的collection属性赋值
<html:select property="userId">
<html:option value="">all</html:option>
<html:options collection="userNameMap" property="key" labelProperty="value" />
</html:select>
userNameMap 为一以UserAccount对象的userID属性为key,userName属性为value的map。
property="key" 意思指 以collection属性指定的map的key值做为option 的property。
labelProperty="value" 意思是以collection属性指定的map的value值(对应property="key" )做为option 的 labelProperty。
--------------------------------------------------------
以上两种方法均可达到以集合中所有UserAccount对象的userID属性作为property,userName属性为labelProperty的效果。
Struts html:options 标签
最新推荐文章于 2020-11-12 14:08:47 发布