Re: Binding to dynamic checkbox in an array doesn't work.
Lachezar Dobrev <[email protected]> Wed, 1 Sep 2010 13:27:49 +0300
| Newsgroups | gmane.comp.java.springframework.user |
|---|---|
| Message-ID | <[email protected]> |
The value of a check-box has special meaning.
Check-box elements are only sent when checked, and their value is
the value of the value attribute (duh!). Unlike other components the
value of the check-box is not changed but the browser!
You should simply (REALLY!) set the value to "true". This way if the
check box is checked the server will get true for the attribute, and
if the check-box is cleared the server will get nothing.
To make it right do:
<c:choose>
<c:when test="${status.value}">
<input type="text" name="${status.expression}" value="true"
checked="checked"/>
</c:when>
<c:otherwise>
<input type="text" name="${status.expression}" value="true" />
</c:otherwise>
</c:choose>
The check-box is the weirdest component!
The value does NOT modify whether the box is checked, or not!
And using this Javascript solution is... Well... Ugly (sorry).
2010/8/31 Kannan Jayaprakasam <[email protected]>:
> The value attribute of the checkbox was 'false' even though the checked attribute was 'true' when it was checked. That seems weird, I got it resolved by setting this.value=this.checked; in the onclick action.
>
> Thanks
> kannan
>
> -----Original Message-----
> From: Lachezar Dobrev [mailto:[email protected]]
> Sent: Saturday, August 28, 2010 4:47 PM
> To: List for Spring users
> Subject: Re: [Springframework-user] Binding to dynamic checkbox in an array doesn't work.
>
> Check-box value should not be 'false', because whether you check the
> box (and receive false) or not (and receive nothning)
> Try value="true". Not value="${true}" although it will work.
> Also you might want to create a hidden input to turn off unchecked
> boxes: http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/web/bind/WebDataBinder.html#setFieldMarkerPrefix%28java.lang.String%29
>
> 2010/8/27 Kannan Jayaprakasam <[email protected]>:
>> Inside nested forEach loops I'm dynamically creating textbox and checkboxes
>> as below. Value set in the textbox is getting passed to the controller, when
>> the form is submitted, but the checkbox value is always passed as false,
>> even when checked. I even looked at the request parameter available to the
>> Controller, it is false as well.
>>
>>
>>
>> <spring:bind
>> path="refreshCache.instanceDetails[${instanceLoopStatus.index}].modulesRunning[${moduleLoopStatus.index}].serviceUrl">
>>
>>
>> <input type="text" name="${status.expression}" value="${status.value}"/>
>>
>>
>> </spring:bind>
>>
>>
>> <spring:bind
>> path="refreshCache.instanceDetails[${instanceLoopStatus.index}].modulesRunning[${moduleLoopStatus.index}].checked">
>>
>>
>> <input type="checkbox" name="${status.expression}" value="${status.value}"/>
>>
>>
>> </spring:bind>
>>
>>
>>
>> Why is this happening? I'm clueless. Please help.
>>
>>
>>
>> --Kannan
>>
>> ------------------------------------------------------------------------------
>> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
>> Be part of this innovative community and reach millions of netbook users
>> worldwide. Take advantage of special opportunities to increase revenue and
>> speed time-to-market. Join now, and jumpstart your future.
>> http://p.sf.net/sfu/intel-atom-d2d
>> _______________________________________________
>> Springframework-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/springframework-user
>>
>>
>
> ------------------------------------------------------------------------------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> _______________________________________________
> Springframework-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/springframework-user
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Springframework-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/springframework-user
>
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd