使Struts2的checkboxlist默认选中方法如下:
?
1、JSP页面
class="java" name="code"><s:checkboxlist label="测试" name="checkbox" list="codeList" listKey="key" listValue="value" value="%{checkbox}" />
?
返回的value与name保持一致,都为数组,并且name的数组类型要与listKey类型一致
?
2、Action
private List<CodeModel> codeList = new ArrayList<CodeModel>(); private String[] checkbox; public String view(){ String[] str = {"1","2"}; codeList = getList(); //通过action的getCheckbox方法为checkbox赋值 checkbox = str; return SUCCESS; } public List<CodeModel> getCodeList() { return codeList; } public void setCodeList(List<CodeModel> codeList) { this.codeList = codeList; } public String[] getCheckbox() { return checkbox; } public void setCheckbox(String[] checkbox) { this.checkbox = checkbox; }
??
?