I\'m trying to use views.html.helper.select
(documentation here). I don\'t know scala, so i\'m using java. I need to pass object of type Seq[(String)(String)] t
The right type is: Seq[(String, String)]
. It means a sequence of pairs of String. In Scala there is a way to define pairs using the arrow: a->b == (a, b)
. So you could write e.g.:
@select(field = myForm("selectField"), options = Seq("foo"->"Foo", "bar"->"Bar"))
But there is another helper, as shown in the documentation, to build the sequence of select options: options
, so you can rewrite the above code as:
@select(myForm("selectField"), options("foo"->"Foo", "bar"->"Bar"))
In the case your options values are the same as their label, you can even shorten the code to:
@select(myForm("selectField"), options(List("Foo", "Bar")))
(note: in Play 2.0.4 options(List("Foo", "Bar"))
doesn't compile, so you can try this options(Seq("Foo", "Bar"))
)
To fill the options from Java code, the more convenient way is to use either the overloaded options function taking a java.util.List<String>
as parameter (in this cases options values will be the same as their label) or the overloaded function taking a java.util.Map<String, String>
.