POJO Object binding and checkboxes

Showing 1-8 of 8 messages
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.

Cheers,

Damian.

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:

<tr class="prop">
    <td valign="top" class="name">
        <label for="aktiv">Aktiv:</label>

    </td>
    <td valign="top" class="value ">
        <input type="hidden" name="_aktiv" />
        <input type="checkbox" name="aktiv" checked="checked"
id="aktiv"  />
    </td>
</tr>

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
by play.

Niels
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" />
<input type="hidden" name="object.done" value="false" />

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

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.

Cheers,

Damian.

On Sep 16, 4:13 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> 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" />
> <input type="hidden" name="object.done" value="false" />
>
> On Wed, Sep 15, 2010 at 9:54 AM, GrailsDeveloper
>
>
>
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> 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?

Niels
Re: [play-framework] Re: POJO Object binding and checkboxes Guillaume Bort 9/16/10 1:20 AM
Yes that's right.

>>> fram...@googlegroups.com.


>>> To unsubscribe from this group, send email to play-framewor...@googlegroups.com
>>> .
>>> For more options, visit this group athttp://groups.google.com/
>>> group/play-framework?hl=en.
>>
>> --
>> Guillaume Bort,http://guillaume.bort.fr
>>
>> For anything work-related, use g...@zenexity.fr; for everything else,
>> write guillaume.b...@gmail.com
>
> --
> You received this message because you are subscribed to the Google  
> Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en
> .
>

Re: POJO Object binding and checkboxes GrailsDeveloper 9/16/10 2:18 AM
Is it right that there exist a spec (which) or is it right that this
is an open question?
Niels

On 16 Sep., 10:20, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Yes that's right.
>
Re: [play-framework] Re: POJO Object binding and checkboxes Guillaume Bort 9/16/10 3:06 AM
I don't know if there is a spec for that. I just know that it works.

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com