当前位置:编程学习 > JSP >>

Struts 中 Multibox 的用法

答案:
在 ActionForm 中定义一个数组 String[] selectedOptions 用于存放复选框被选中的值,

数组 LabelValueBean[] possibleOptions 用于显示所有的复选框的值。

import org.apache.struts.util.LabelValueBean; . . . public class MyActionForm extends ActionForm {   private LabelValueBean[] possibleOptions;   private String[] selectedOptions;    public MyActionForm()   {      // Initialise the LabelValueBeans in the possibleOptions array.     LabelValueBean[] lvBeans = new LabelValueBean[4];      lvBeans[0] = new LabelValueBean("Alpha", "A");     lvBeans[1] = new LabelValueBean("Beta", "B");     lvBeans[2] = new LabelValueBean("Charlie", "C");     lvBeans[3] = new LabelValueBean("Delta", "D");      this.possibleOptions = lvBeans;   }    public LabelValueBean[] getPossibleOptions()   {     return possibleOptions;   }    public String[] getSelectedOptions()   {     return selectedOptions;   }    public void setSelectedOptions(String[] selectedOptions)   {     this.selectedOptions = selectedOptions;   } }

在 JSP 中使用以下代码:



<logic:iterate name="myActionForm" 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>

上一个:Java XML教程(附:源程序)
下一个:如何在项目实践中扩展Struts

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,