Announcement Announcement Module
Collapse
No announcement yet.
bind to checkbox when validation fail for another form value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • bind to checkbox when validation fail for another form value

    I have defined my checkbox as shown below (according to one of the previous post on the subject)

    <spring:bind path="form.someBooleanProperty">
    <input type="hidden" name="_${status.expression}">
    <input type="checkbox" name="${status.expression}" id="${status.expression}"
    <c:if test="${status.value}">checked</c:if> />
    </spring:bind>

    When validation fails for another form value, then the value is set back to the original value and the user check or unckeck will be lost. So the user will have to check/uncheck the box again. The input type=text seem to retain the user changes but not the checkbox?

  • #2
    check if the following thread could help !!

    http://forum.springframework.org/viewtopic.php?t=5071

    Comment


    • #3
      You don't have a value property for the non-hidden input.

      Comment


      • #4
        It didn't work when I set the value to anything as the documentation suggests:

        http://www.springframework.org/docs/api/org/springframework/web/bind/ServletRequestDataBinder.html#setFieldMarkerPrefix (java.lang.String)

        But it does work if I set the value to status.value as shown below:

        <spring:bind path="command.someBooleanProperty">
        <input type="hidden" name="_someBooleanProperty" value="<c:out value="${status.value}"/>">
        <input type="checkbox" name="someBooleanProperty" id="someBooleanProperty"
        <c:if test="${status.value}">checked</c:if> value="<c:out value="${status.value}"/>" />
        </spring:bind>

        I did find another workaround that may be useful for when you are dealing with a non-boolean property. I used javascript and the onclick event on the checkbox to set the value of the _marker property.

        Comment


        • #5
          this thread too ..

          http://forum.springframework.org/viewtopic.php?t=5071

          Comment


          • #6
            But it does work if I set the value to status.value as shown below:
            That's what I said, more or less... If you don't have a value property set you likely won't get too much data submitted from that control.

            Comment

            Working...
            X