|POJO Object binding and checkboxes||damian||9/14/10 6:57 PM|
When Play binds request parameters to a POJO it ensures that
"Unresolved parameters are safely ignored." The problem with this is
that if a checkbox is unselected, it will not be in the parameter list
and thus a "false" is never bound to the POJO.
I've worked around this by including checkbox parameters in the method
and setting them in the code, rather than relying on them in the POJO
bind. How have other developers worked around this? It doesn't feel
like something that Play can resolve without accidentally changing a
value when it was not required.
|Re: POJO Object binding and checkboxes||GrailsDeveloper||9/15/10 12:54 AM|
That a general problem indeed. I'm not sure, but I think grails solve
this issue by have another parameter with the info that the checkbox
is asked. Here an example:
<td valign="top" class="name">
<td valign="top" class="value ">
<input type="hidden" name="_aktiv" />
<input type="checkbox" name="aktiv" checked="checked"
Then you know if the parameter "aktiv" isn't set, but you get the
parameter "_aktiv", you must set the property to false. Would be
indeed great if this would be supported by CRUD (I don't test it) and
|Re: [play-framework] Re: POJO Object binding and checkboxes||Guillaume Bort||9/15/10 11:13 AM|
It's already done in CRUD, and you can do the same for your own
checkbox. The idea is to declare an hidden field with the same name:
<input type="checkbox" name="object.done" value="true" />
|Re: POJO Object binding and checkboxes||damian||9/15/10 3:53 PM|
That's a good tip thanks.
Note in some quick testing that I've just done, the placement of the
hidden field is important. It must be after the checkbox or the value
will always be that of the hidden field.
> Guillaume Bort,http://guillaume.bort.fr
>> write guillaume.b...@gmail.com
|Re: POJO Object binding and checkboxes||GrailsDeveloper||9/15/10 11:35 PM|
I head a look into the HTML4.01 Spec http://www.w3.org/TR/html401/interact/forms.html.
I didn't found any rule that defines how the controls are submitted.
If I follow http://stackoverflow.com/questions/452066/html-form-with-multiple-hidden-control-elements-of-the-same-name.
It seems that the control name "object.done" will be submitted twice
so described as an get url &object.done=true&object.done=false. So
it's part of the server-implementation and play does the decision to
take only the first in the Binder-Class. Well this explain the nice
behavior of play, but one question remains: Is there any spec which
assure that the values comes in the same order than they defined?
|Re: [play-framework] Re: POJO Object binding and checkboxes||Guillaume Bort||9/16/10 1:20 AM|
Yes that's right.
|Re: POJO Object binding and checkboxes||GrailsDeveloper||9/16/10 2:18 AM|
|Re: [play-framework] Re: POJO Object binding and checkboxes||Guillaume Bort||9/16/10 3:06 AM|