J2EE学习笔记
我们的失落……
posts - 13,comments - 1,trackbacks - 0
ActionForm 中定义一个数组 String[] selectedOptions 用于存放复选框被选中的值,
数组 LabelValueBean[] possibleOptions 用于显示所有的复选框的值。


import org.apache.struts.action.ActionForm;
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>
posted on 2008-03-11 22:50 J2EE学习笔记 阅读(281) 评论(0)  编辑  收藏 所属分类: struts转载

只有注册用户登录后才能发表评论。


网站导航: