You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Ted Husted (JIRA)" <ji...@apache.org> on 2006/07/05 17:39:16 UTC

[jira] Created: (WW-1372) Provide transparent support for session-scope checkboxes

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


[jira] Commented: (WW-1372) Provide transparent support for session-scope checkboxes

Posted by "Gabriel Zimmerman (JIRA)" <ji...@apache.org>.
    [ 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


[jira] Commented: (WW-1372) Provide transparent support for session-scope checkboxes

Posted by "Martin Helff (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] Resolved: (WW-1372) Provide transparent support for session-scope checkboxes

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1372?page=all ]

Don Brown resolved WW-1372.
---------------------------

    Fix Version/s: 2.0.0
                       (was: Future)
       Resolution: Duplicate

Duplicate of WW-992

> 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: 2.0.0
>
>
> 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