I have dynamic number of checkboxes in jsp page as given below.
Actually I use Struts 2 3.8 and WebSphere 7.0 and Map works for rendering the check boxes, but not working when these check boxes post back. The Boolean class is rendered correctly, but during the post back in Struts 2, it becomes ognl.NoConversionPossible
and ends up with No result defined for action CLASS ...and result input
error.
I replaced Boolean with String class, i.e.
maps.put(new Integer(0), new String("true"));
and it works for me.
Because your checkboxes are all named the same (checkbox
), Struts2 is just passing the following:
checkbox=true&checkbox=true&checkbox=true
Does that mean that you omitted the second, third, or fourth checkbox?
What you actually want is not an array of booleans, but a map of Integer to Boolean. Here's an example:
public class MyAction extends ActionSupport {
private Map<Integer, Boolean> checkboxes;
...
public Map<Integer, Boolean> getCheckboxes() {
return checkboxes;
}
public void setCheckboxes(Map<Integer, Boolean> checkboxes) {
this.checkboxes = checkboxes;
}
}
<s:iterator value="details" status="stat">
<%-- this outputs checkboxes[0], checkboxes[1], etc. --%>
<s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" />
</s:iterator>