I have a JSP page with several questions and an ActionForm with a map of names and input values.
When I load the page, the values ββ(checked attribute) for the radio inputs arent checked, but there are checkboxes.
The form defines:
<bean:define id="form" name="questionForm" type="com.example.QuestionForm"/>
Radio (jsp):
<html:radio property="<%=\"boolean(\" + questionBase + \"V\" + respLabel + \")\"%>" styleClass="pepperoni1" value="1" >Yes</html:radio> <html:radio property="<%=\"boolean(\" + questionBase + \"V\" + respLabel + \")\"%>" styleClass="pepperoni0" value="0" >No</html:radio>
Radio (html):
<input type="radio" class="pepperoni1" value="1" name="boolean(pepperoniVNever)">Yes <input type="radio" class="pepperoni0" value="0" name="boolean(pepperoniVNever)">No
Checkbox (jsp):
<html:checkbox property="<%=\"boolean(\" + questionBase + \"V\" + respLabel + \")\"%>" styleClass="pepperoni" />
Checkbox (html):
<input type="checkbox" class="pepperoni" checked="checked" value="on" name="boolean(pepperoniV1)">
The checked attribute is not set, but the values ββare not empty when accessed via the load / form submit by getBoolean / setBoolean .
The following correlation methods are available in my ActionForm class:
public void setValue(String key, String value) { if (value != null) values.put(key, value); } public String getValue(String key) { return values.get(key); } public boolean getBoolean(String key) { if (values.get(key) != null){ if(values.get(key).equalsIgnoreCase("1")){ return true; } else if(values.get(key).equalsIgnoreCase("0")){ return false; } return "yes".equalsIgnoreCase(values.get(key)); } return false; } public void setBoolean(String key, boolean value) { if(value){ values.put(key, "yes"); } }
I am using struts 1.2.7, Hibernate 3, DisplayTag 1.0, OpenJDk 6 and Tomcat 6 on Ubuntu 14.04.
Update
However, the following do radio inputs work (as you can see by the "checked" attribute:
Radio (jsp):
<html:radio property="<%=\"value(\" + questionBase + \"B)\"%>" value="No">No</html:radio> <html:radio property="<%=\"value(\" + questionBase + \"B)\"%>" value="Yes">Yes</html:radio>
Radio (html):
<input name="value(noteB)" value="Yes" checked="checked" type="radio"> <input name="value(noteB)" value="No" type="radio">
But after editing the inputs using boolean to use value the checked attribute is still not set at boot.
Update (5/10/15)
After making the changes recommended by shinjw, the values ββare saved correctly (this was a separate issue), but the checked attribute is still not set for some of the switches when getBoolen returns true.