Results 1 to 6 of 6

Thread: bind to checkbox when validation fail for another form value

  1. #1

    Default 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?
    cheers,
    Lili

  2. #2

    Default

    check if the following thread could help !!

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

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

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

  4. #4

    Default

    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.
    cheers,
    Lili

  5. #5

  6. #6
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    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.

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 1
    Last Post: Apr 29th, 2009, 12:36 PM
  3. Replies: 6
    Last Post: Sep 24th, 2006, 11:58 AM
  4. Replies: 0
    Last Post: Jun 10th, 2005, 08:22 AM
  5. Newbie bind question: bind an entire form?
    By kendelong in forum Web
    Replies: 0
    Last Post: Feb 4th, 2005, 04:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •