strute-html:options

java 代码
  1. class bean{      
  2.   private Collection beanCollection;      
  3.   public Collection getBeanCollection();      
  4.   public Collection setBeanCollection();      
  5. }     
  6.   
  7. class action{   
  8.   public actionforward edit(......){   
  9.        
  10.    Vector entries = new Vector(10);               
  11.    entries.add(new LabelValueBean("Label 0""Value 0"));               
  12.    entries.add(new LabelValueBean("Label 1""Value 1"));     
  13.    //设置下拉框内容   
  14.     bean.setBeanCollection(entries);   
  15.     request.setattribute("selectBean",bean);   
  16.   }   
  17. }  
     < html:select property= "beanCollectionSelect" size= "10" multiple= "true" >
        < html:optionsCollection name=
"selectBean" property= "beanCollection" / >
      < /html:select >
     如果上面java代码中红色部分替换为:
java 代码
  1. 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 代码
  1. private String singleSelect = "Single 5";   
  2.   
  3.     public String getSingleSelect() {   
  4.         return (this.singleSelect);   
  5.     }   
  6.   
  7.     public void setSingleSelect(String singleSelect) {   
  8.         this.singleSelect = singleSelect;   
  9.     }   



    多选必须是数组:
java 代码

  1. private String[] beanCollectionSelect = { "Value 1""Value 3",   
  2.                                               "Value 5" };   
  3.   
  4.     public String[] getBeanCollectionSelect() {   
  5.         return (this.beanCollectionSelect);   
  6.     }   
  7.   
  8.     public void setBeanCollectionSelect(String beanCollectionSelect[]) {   
  9.         this.beanCollectionSelect = beanCollectionSelect;   
  10.     }   



    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值