4

How do you handle multiple checkboxes in Play Framework 2.0 JAVA via GET?

The url looks similar to: http://localhost:9000/games?type=platform&type=role. How can I get both "type" values in a "Set" variable in my controller?

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">

Thank you!

1 Answer 1

6

Have a look at http://www.playframework.org/documentation/2.0/ScalaForms , section "Repeated Values":

1) Name the fields type[0], type[1], ....

2) You'll then have in the controller a List[String], out of which you have to look for the checked values.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Samuel! But that would require the whole controller to be written in Scala instead of Java?
As far as I could determine in playframework.org/documentation/2.0/JavaForms, the same in Java should work too.
Note: playframework.org has been changed to playframewor.com. Please update the above links and delete this message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.