:<html:multibox property="secondBox" checked="checked">

解决方案 »

  1.   

    谢谢回答,可是:<html:multibox〉没有checked 属性。
      

  2.   

    那就把那个属性secondBox的值赋为true
      

  3.   

    secondBox属性的类型要为boolean或者Boolean
      

  4.   

    在body中加一个onload="selectAll()"
    javascript把所有的选中
    function selectAll(){
      // do stuffing
    }
      

  5.   

    <html:multibox 对应的formBean中的属性应该是String[]吧,如:
    private String[] secondBox;
    页面可能有多处
    <html:multibox property="secondBox" value="a"></html:multibox>
    <html:multibox property="secondBox" value="b"></html:multibox>
    <html:multibox property="secondBox" value="c"></html:multibox>
    那么要设置默认值我想应该是在页面返回前先设置formBean中的属性值,如secondBox = {"a","b"},这样页面显示前两个选项是选中的,这是一般人的想法,我没用过<html:multibox,不知道struts是不是这样实现的。
      

  6.   

    在body加上onload="init()"
    javascript加上
    function init(){
        document.[your form name].secondBox.checked = true;
    }
      

  7.   

    对于<html:标签在每次页面调出时struts都是根据formBean中的值进行赋值,你如果在页面直接设值会和formBean中的值有冲突,所以struts没有在页面对<html:设置默认值的方法。
      

  8.   

    multibox对应form中的string[]参数,如果给form中的string[]设置初始值,那么出来的checkbox就是被选中的的。如lujh99(闲云)所说的,form中是这样
    private String[] selectedOptions = {"1","2","3"};
    private LabelValueBean[] possibleOptions;
    //构造函数
     public MyForm()
       {  LabelValueBean[] lvBeans = new LabelValueBean[3];
          lvBeans[0] = new LabelValueBean("abc", "1");
         lvBeans[1] = new LabelValueBean("bcd", "2");
         lvBeans[2] = new LabelValueBean("def", "3");
     
         this.possibleOptions = lvBeans;
       }
       jsp中是:
    //这里的myForm是配置文件里配置的。对应MyForm类。
    <logic:iterate name="myForm" id="item" property="possibleOptions">
       <html:multibox property="selectedOptions" >
         <bean:write name="item" property="value" />
       </html:multibox>
         <bean:write name="item" property="label" /><br />
     </logic:iterate>