html:select html:select 生成一个HTML的<select>标记,可以使用multiple 属性创建单选或多选列表。 multiple属性设置是否可以多选 size 设置页面显示多少个,单选默认为1,多选默认为全部。 html:option label值有两个来源: 1. <html:option>和</html:option>之间的内容 <html:option value=”1”>大一</html:option> 2. 使用html:option标签的key、locale和bundle属性 <html:option value=”1” bundle=”school” key=”grade”/> bundle指定资源束,locale指定特定的语言环境,key指定资源束中的特定键。 在struts-config.xml中定义了如下的资源束: struts-config.xml: <message-resources parameter=”cn.rolia.struts. ApplicationResources” key=”school”/> html:options 可以将可选的值放到一个集合中,然后用html:options将此集合作为select的值。 先在页面范围里定义一个Vector,在html:option中的collection属性指定为这个Vector: <% Vector colors = new Vector(); colors.add(new org.apache.struts.util.LabelValueBean("粉红色","pink")); colors.add(new org.apache.struts.util.LabelValueBean("紫色","purple")); colors.add(new org.apache.struts.util.LabelValueBean("灰色","gray")); colors.add(new org.apache.struts.util.LabelValueBean("褐色","brown")); pageContext.setAttribute("color",colors); %> <html:select property="color2" multiple="true"> <html:options collection="color" property="value" labelProperty="label" /> </html:select> property表示实际值,labelProperty表示页面显示的值。 html:optionsCollection 在FormBean里定义一个Bean而不是像html:options那样在页面里定义Collection。

评论