Reputation: 166
I am using Spring 3.0.6 and their tag library. I am using the form:checkbox tag. From what I read and researched, it is supposed to create a hidden field with the same name and a leading _ character. This tells spring whether the checkbox was checked or not so that it will properly set my model attribute when the checkbox is not checked or when it is disabled.
The problem is that I am not seeing a hidden field created for my form:checkbox. I thought it might be my version of Spring, but I saw another post where a developer appeared to be using Spring 3.0.5 and it was generating the hidden field for him.
Here is a code snippet from my JSP where I create the checkbox.
<form:checkbox path="contactInformation.optOutOfProgram" value="Y" id="chkOptOutOfProgram" disabled="true" />
Here is the resulting HTML that is generated:
<input id="chkOptOutOfProgram" name="contactInformation.optOutOfProgram" disabled="disabled" type="checkbox" value="Y"/>
There is no hidden field with the name _contactInformation.optOutOfProgram
generated on the page. I read that I could manually code this but I also read it is supposed to automatically create the hidden field.
Upvotes: 1
Views: 448
Reputation: 1
Disabled checkbox doesn't get submitted, so NO need a hidden field for passing the value back.
Upvotes: -1
Reputation: 166
I found the issue when looking at the Tutorials that Braj pointed out even though the Tutorial does no explicitly explain this. One of the things that is different from my code and the code in the tutorials as well as all of the other code that I saw in my research is that I have disabled="true"
in my form:checkbox declaration. I disable it using jQuery based on stuff entered by the user in other fields. Apparently if you set the field using the disabled attribute for the form:checkbox Spring tag, it does not generate the hidden field. As soon as I removed that from form:checkbox, the generated html content had the hidden field.
I guess I need to report that as a possible bug to the Spring developers.
Upvotes: 1