<html:multibox>相当于多个<html:checkBox>(不过它比后者有更好优点)
下面我详细的说明:
1
在ActionForm Bean中定义一个数组,来存放所有的CheckBOx的值。
例如: private String String[] result=new String[0];
public void setResult(String[] result){ this.result=result; }
public String[] getResult(){ return result; }
2在jsp页面的表单中加入<html:multibox>元素是通过设置属性property="result"来把它和ActionForm Bean中的数组来关联的。
对于每一个<html:multibox>元素,设置它的值的。有两种方式如下:
1:<html:multibox property="result" value="resultValue"/> 2 :<html:multibox property="result" >resultValue</html:multibox>
说明:当用户提交表单时,所有被选中的复选框的值都被存放到ActionForm Bean的数据中,如果某个复选框没有被选中那数组中就不会包含它的值 。
优点:与<html:checkbox>相比。<html:multibox>具有更高的灵活性。
<html:mutibox>可以动态决定被选中的复选框的数目,只要这些复选框的property的相同,值不同。他们就会和ActionForm的同一个数组对应。此外,<html:checkbox>只能和ActionForm的boolean类型的属性对应,而<html:multibox>没有这样的限制。