[2.0] Multiple checkboxes in a form via GET (Java)

892 views
Skip to first unread message

ccchr

unread,
Jul 17, 2012, 6:58:36 PM7/17/12
to play-fr...@googlegroups.com
I've been searching for a long time, how do you handle multiple checkboxes in JAVA via GET?

How do I access both "type" values in my controller?

Thank you!

ccchr

unread,
Jul 17, 2012, 7:11:36 PM7/17/12
to play-fr...@googlegroups.com
My form looks like this:

<input type="checkbox" name="type[]" class="" value="all-types">
<input type="checkbox" name="type[]" class="" value="platform">
<input type="checkbox" name="type[]" class="" value="role">
...

and in my controller I've used
DynamicForm form = form().bindFromRequest();
System.out.println(form.field("type[]").value());

but it only prints the first item in the list i.e. "platform".

Any ideas of what am I doing wrong?

Thank you!

Julien Richard-Foy

unread,
Jul 18, 2012, 1:48:15 AM7/18/12
to play-fr...@googlegroups.com
If I remember correctly, the naming you want to use was not supported in Play 2.0, you had to set indexes in your input names: <input name="type[0]" …


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/20IfqP7HRIsJ.
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.

ccchr

unread,
Jul 18, 2012, 3:14:00 PM7/18/12
to play-fr...@googlegroups.com
And once you set the indexes how would you access it in the controller?


On Wednesday, July 18, 2012 1:48:15 AM UTC-4, Julien Richard-Foy wrote:
If I remember correctly, the naming you want to use was not supported in Play 2.0, you had to set indexes in your input names: <input name="type[0]" …



On 18 juil. 2012, at 01:11, ccchr <cfo...@gmail.com> wrote:

My form looks like this:

<input type="checkbox" name="type[]" class="" value="all-types">
<input type="checkbox" name="type[]" class="" value="platform">
<input type="checkbox" name="type[]" class="" value="role">
...

and in my controller I've used
DynamicForm form = form().bindFromRequest();
System.out.println(form.field("type[]").value());

but it only prints the first item in the list i.e. "platform".

Any ideas of what am I doing wrong?

Thank you!


On Tuesday, July 17, 2012 6:58:36 PM UTC-4, ccchr wrote:
I've been searching for a long time, how do you handle multiple checkboxes in JAVA via GET?

How do I access both "type" values in my controller?

Thank you!

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/20IfqP7HRIsJ.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.

Julien Richard-Foy

unread,
Jul 18, 2012, 4:50:19 PM7/18/12
to play-fr...@googlegroups.com
You can bind it using a repeated mapping in your controller Form object.


To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/NIxSsRYhDFUJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

ccchr

unread,
Jul 19, 2012, 2:40:44 PM7/19/12
to play-fr...@googlegroups.com
Julien,
Thank you for the reply again... Would you happen to have an example? I am a little new to Play.

Thanks!

Julien Richard-Foy

unread,
Jul 19, 2012, 4:28:53 PM7/19/12
to play-fr...@googlegroups.com
If I remember correctly that's something like:
Form("type"->seq(text))
You may want to look at the documentation and the "forms" sample :)
Cheers


To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/K1LlHiutL2oJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

Martin Preusse

unread,
Jul 25, 2012, 4:45:33 AM7/25/12
to play-fr...@googlegroups.com
Any solution for this? I still have no idea how I can access the the checked boxes in my controller. And I really want this, it's driving me crazy ;)
Reply all
Reply to author
Forward
0 new messages