[ http://issues.apache.org/struts/browse/WW-1372?page=comments#action_37658 ]
Gabriel Zimmerman commented on WW-1372: --------------------------------------- One solution to get this rolling: Create a booleanCheckbox tag (or assume that a checkbox is boolean if value="true"). onclick creates a hidden field in the form of the same name as the checkbox with value="false" if it is a checking action, or removes that hidden field if it is not a checking action. Also, when the page is loaded a hidden field would be added if the given boolean checkbox is set to false: <input type="checkbox" name="myCheckbox" value="true" onclick="updateCheckboxHiddenField(this)"/> <input type="hidden" name="myCheckbox" value="false" id="someUniqueKeySoWeKnowThisIsStrutsCreated"/> The drawback of this solution is it could in theory cause a clash with user created Javascript, and it requires a Struts created Javascript method on the page (latter very minor since we do this elsewhere). > Provide transparent support for session-scope checkboxes > -------------------------------------------------------- > > Key: WW-1372 > URL: http://issues.apache.org/struts/browse/WW-1372 > Project: Struts 2 > Type: Improvement > Reporter: Ted Husted > Fix For: Future > > HTML checkboxes have a quirk in that if the checkbox is clear (false), > browsers are not required to submit the control. If the control is set, the > control is submitted as "control_name=control_name", but in the case of a > clear checkbox, nothing is expected to be submitted. > Accordingly, it is impoort to set the property backing the checkbox to false > when a form is rendered. If the checkbox submits back clear, it will remain > false, if the form submits back, the field can be set to true to reflect the > change. > However, if the form is being held in session scope, prematurely setting the > value to false can be dangerous. If the form is never submitted back, the > value will remain false. If the form is later committed to persistent store, > an inadvertent change in state will occur. This can be a real problem when > using POJOs backed by a persistence system like Hibernate. > One workaround is to create action-properties for session-scope checkboxes > and update the POJO in the action. > Another solution is to use a naming convention in conjection with an > interceptor to set missing checkboxes to true. > For additional background, see > [http://forums.opensymphony.com/thread.jspa?forumID=1&threadID=23601]. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira
