<html:select property="beanCollectionSelect" size="10" multiple="true">
<html:optionsCollection name="testbean" property="beanCollection"/>
</html:select>FORMname is testbeanprivate String[] beanCollectionSelect = { "Value 1", "Value 3",
                                              "Value 5" };public String[] getBeanCollectionSelect() {
        return (this.beanCollectionSelect);}public void setBeanCollectionSelect(String beanCollectionSelect[]) {
        this.beanCollectionSelect = beanCollectionSelect;}private Collection beanCollection = null;   public Collection getBeanCollection() {
        if (beanCollection == null) {
            Vector entries = new Vector(10);            entries.add(new LabelValueBean("Label 0", "Value 0"));
            entries.add(new LabelValueBean("Label 1", "Value 1"));
            entries.add(new LabelValueBean("Label 2", "Value 2"));
            entries.add(new LabelValueBean("Label 3", "Value 3"));
            entries.add(new LabelValueBean("Label 4", "Value 4"));
            entries.add(new LabelValueBean("Label 5", "Value 5"));
            entries.add(new LabelValueBean("Label 6", "Value 6"));
            entries.add(new LabelValueBean("Label 7", "Value 7"));
            entries.add(new LabelValueBean("Label 8", "Value 8"));
            entries.add(new LabelValueBean("Label 9", "Value 9"));            beanCollection = entries;
        }        return (beanCollection);
    }    public void setBeanCollection(Collection beanCollection) {
        this.beanCollection = beanCollection;
    }beanCollectionSelect 为 select 中 all selected options
beanCollection  为 select 中 all  optionsstruts 1.02不支持这个功能,要后续版本 1.1
具体可参考 www.apache.org 中的例子

解决方案 »

  1.   

    <html:options>  没看到有这个功能
      

  2.   

    是有<html:options>这个功能,书上的例子是这样写的:
    <html:select property="parentid">
     <html:options collection="parentids" property="value" labelProperty="label"/>   </html:select>就不知在actionfrom中如何定义?
      

  3.   

    bcdavid(莉莉) :new LabelValueBean在那定义?
      

  4.   

    <html:options> 我的意思是 没办法实现  form bean 里面与
    页面optons交互的功能
    只是与<html:select property="parentid">交互<html:options collection="parentids" property="value" labelProperty="label"/>上的collection 是jsp页面上 定义的建议你用上面我说的方法 
      

  5.   

    bcdavid(莉莉):你上面的方法中,new LabelValueBean在哪定义,如何定义?并且下载struts1.1配置后,启动出错,1.0.2则启动正常。<html:options> 可以实现  form bean 里面与页面optons交互的功能,但有一个问题是从form bean传过来的如是中文,则为乱码。
      

  6.   

    <html:select property="parentId">
                                               <html:options name="answers" property="value"  labelProperty="label"/>
                                          </html:select>
    出错:cannot find bean under name answers但在action form 中已定义了answers:
      private Collection answers = null;
      public Collection getAnswers() {
         if (answers == null) {
              Vector entries = new Vector(4);
              entries.add(new labelvaluebean("Label1","Value1"));
              entries.add(new labelvaluebean("Label1","Value1"));
              entries.add(new labelvaluebean("Label2","Value2"));
              entries.add(new labelvaluebean("Label3","Value3"));
              answers = entries;
             }
          return (answers);
          }
       public void setAnswers(Collection answers) {
            this.answers = answers;
        }