Announcement Announcement Module
Collapse
No announcement yet.
checkbox issue: value = true ( always ) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • checkbox issue: value = true ( always )

    hi all
    I have looked in numerous checkbox issues in this forum.
    but I am unable to locate which highlights the simple issue that I am trying to figure out.

    the value of the checkbox seems to always be true.

    jsp code
    Code:
    <form:checkbox path="pollTO.securePoll" />
    initBind() method in controller.
    Code:
    pollTO.setSecurePoll(ServletRequestUtils.getBooleanParameter(request, "pollTO.securePoll", false));
    view source
    [code]
    <input id="pollTO.securePoll1" type="checkbox" value="true" name="pollTO.securePoll"/>
    <input type="hidden" value="on" name="_pollTO.securePoll"/>
    [code]

    Now when the page renders then the checkbox for securePoll is unchecked but the value is true ?

    any idea or maybe I need to go through the w3schools tutorial on input types :/

    Thanks.

  • #2
    The value of a checkbox indicates the value that should be submitted IF the checkbox is checked. If the value is "true" that just means that WHEN the checkbox is checked, the value passed in the request is "true". When the checkbox is not checked, no value is passed (that's why Spring puts in the hidden field -- so it knows when a checkbox was there but wasn't checked).

    The value field might just as well have been "abracadabra" or whatever. It's just an indication of what to pass.

    Not sure what you're doing there in initBind, by the way. The whole idea of Spring binding is that you never need to explicitly get the request parameters or set your object properties -- Spring handles all that for you.

    Comment

    Working...
    X