java 代码
- class bean{
- private Collection beanCollection;
- public Collection getBeanCollection();
- public Collection setBeanCollection();
- }
- class action{
- public actionforward edit(......){
- Vector entries = new Vector(10);
- entries.add(new LabelValueBean("Label 0", "Value 0"));
- entries.add(new LabelValueBean("Label 1", "Value 1"));
- //设置下拉框内容
- bean.setBeanCollection(entries);
- request.setattribute("selectBean",bean);
- }
- }
< html:optionsCollection name= "selectBean" property= "beanCollection" / >
< /html:select >
如果上面java代码中红色部分替换为:
java 代码
- reqeust.setAttribute("selectList",entries);
< html:select property="beanCollectionSelect" size="10" multiple="true" >
< html:options name="selectList" labelProperty="label" property="value"/ >
< /html:select >
需要设置Selected,selected有两种,单选和多选:
在ActionForm中必须有:
java 代码
- private String singleSelect = "Single 5";
- public String getSingleSelect() {
- return (this.singleSelect);
- }
- public void setSingleSelect(String singleSelect) {
- this.singleSelect = singleSelect;
- }
多选必须是数组:
java 代码
- private String[] beanCollectionSelect = { "Value 1", "Value 3",
- "Value 5" };
- public String[] getBeanCollectionSelect() {
- return (this.beanCollectionSelect);
- }
- public void setBeanCollectionSelect(String beanCollectionSelect[]) {
- this.beanCollectionSelect = beanCollectionSelect;
- }