I'm using struts 2. I have an object that contains some booleans. I have a HashMap that contains many of the previous objects defined by some key.
In my jsp a table is populated with radio buttons. One line for each key of the map etc. When I post back the form I want to save the options set by the user. But the map does not seem to get populated.
My code is like:
MyObject ( with two boolean parameters )
private Map<String, MyObject> ... (with getter & setter ).
in my jsp the html generated is:
<input type="radio" name="myMap[123].booleanParameter1" id="someId"
checked="checked" value="true">
etc
Can someone help on how the "name" of the radio button should be set so as struts can populate the map?
public class MyObject implements Serializable{
private Boolean booleanParameter1;
private Boolean booleanParameter2;
getters & setters here
}
Map<String,MyObject> myMap ... in Action
JSP...
<s:iterator ...iterates default map values>
<s:radio label="parameter1" name="myMap['%{key}'].booleanParameter1" list="#{'true':'Yes','false':'No'}" value="%{value.booleanParameter1}" />
<s:radio label="parameter2" name="myMap['%{key}'].booleanParameter2" list="#{'true':'Yes','false':'No'}" value="%{value.booleanParameter2}" />
</s:iterator>
Solution found. The class "MyObject" did not have a Default Constructor. Struts/ognl needs the default constructor to create an object.