Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2499

CheckboxInterceptor sets disabled checkboxes to false even if checked

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.9
    • 2.1.2
    • Core Interceptors
    • None

    Description

      Disabled fields by W3 specifications are not "successful" in that they won't get posted on form submission (http://www.w3.org/TR/html4/interact/forms.html#h-17.12.1).

      The resulting request parameters for a <s:checkbox disabled="true" /> field look as if the checkbox were enabled and not checked (i.e., the '_checkbox' parameter is present but not the parameter for the checkbox itself). Therefore the CheckboxInterceptor sets a new request parameter for the checkbox to false.

      However, if a checkbox is disabled this isn't at all what one would want – rather I would think the CheckboxInterceptor should not set a new request parameter if the checkbox in question is disabled.

      I think a straight forward solution would be to disable the '_checkbox' hidden field if the checkbox itself is hidden, though I'm not finding anything in the W3 spec that says hidden fields can be disabled (http://www.w3schools.com/tags/tag_input.asp says they cannot, if you take W3Schools as an authoritative source). With the hidden field disabled, it too would not be posted on form submission and the problem would correct itself. However, the catch here is that the disabled attribute on an input field can be changed via script, so knowledge of the disabled fields needs to be at form submission rather than at page rendering. Perhaps the hidden field could still be used with some documentation in the tag reference/javadoc stating that if scripting is used to enable or disable a checkbox that the appropriate hidden field must be enabled or disabled as well?

      Another potential solution is to add another hidden field for checkboxes that denote the checkbox as disabled (at page rendering anyway). For instance a field starting with the name '_checkbox_disabled'. Before setting a new request parameter for the checkbox, the CheckboxInterceptor could look for the appropriate '_checkbox_disabled' field. If scripting were used to enable the disabled field, the script should also need to change the value of the '_checkbox_disabled' field such that the CheckboxInterceptor knows what to do.

      Attachments

        Activity

          People

            mrdon Donald J. Brown
            tjstavenger Tim Stavenger
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: