我需要在S2中創建多個複選框,如下所示。在Struts2中創建多個複選框
使用此代碼,我只得到一個複選框
public class EmployeeListBean {
private String empCode = null;
private String empName = null;
public EmployeeListBean(String empCode,String empName)
{
//constructor
}
//setter and getter methods
}
在動作類
public ArrayList<EmployeeListBean> getListOfEmployees()
{
return listOfEmployees;
}
在執行()
listOfEmployees = new ArrayList<EmployeeListBean>();
listOfEmployees.add(new EmployeeListBean("1", "Smith"));
在JSP中,
<s:iterator value="listOfEmployees">
<s:checkbox name="someselectedname" label="%{empName}" fieldValue="%{empCode}"/><br/>
</s:iterator>
我遵循正常的方式。這裏我想在三個複選框中只選擇一個複選框。所以我們可以在JS或Jquery中完成。在HTML中,它就像
<label>abc: </label>
<input type="checkbox" name="ballet" />
<input type="checkbox" name="ballet" />
<input type="checkbox" name="ballet" />
<br/>
<label>def: </label>
<input type="checkbox" name="ballet1" />
<input type="checkbox" name="ballet1" />
<input type="checkbox" name="ballet1" />
但我想要以上格式。如何在S2中做到這一點。
那麼我建議使用單選按鈕而不是複選框。 – Ranjitsinh