[ http://issues.apache.org/struts/browse/WW-1372?page=comments#action_37872 ] Martin Helff commented on WW-1372: ----------------------------------
i would prefer the server-side-solution: (like posted by Patrick Lightbody in WW-Forums) Reason: Javascript might or might not work, always depending on the users browser-settings and therefore isn't reliable if you want to count on the results. Solution: The checkbox tag creates a extra hidden field with a special naming convention. Example: <input type="checkbox" name="checkboxname" value="checkedvalue"> <input type="hidden" name="__CHECKBOXDEFAULT_checkboxname" value="uncheckedvalue"> Did something like this for SAF1 where i simply searched inside of the reset-method of the ActionForm for parameters starting with "__CHECKBOXDEFAULT_". If found, reset the property "checkboxname" to the "uncheckedvalue". In SAF1, processPopulate() then automatically overwrites the submitted default values if the checkbox was checked. Drawbacks of my own solution were: Not integrated in the struts checkbox tag, i had to place the hidden fields manually and i always had to use a special base class for my ActionForms to get the reset-functionality. Would be really nice if something like this could be already included transparently in SAF2. > Provide transparent support for session-scope checkboxes > -------------------------------------------------------- > > Key: WW-1372 > URL: http://issues.apache.org/struts/browse/WW-1372 > Project: Struts 2 > Issue 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
