Struts 中 Multibox 的用法

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

在 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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航