I need to access a Java list from html code in play.
My list is returned by a public static method:
ComboboxOpts.getListOfValues()
I am using this method several times in my scala code want to assign it to some variable. Maybe something similar to this
@mylist = ComboboxOpts.getListOfValues()
So that I can use it like this
@for(i <- 0 to mylist.size -1){
//Do stuff
}
rather than this
@for(i <- 0 to ComboboxOpts.getListOfValues.size -1){
//Do stuff
}
You can use
defining()to set new variables, such as:However, for your case, you can just iterate over a list as follows:
This will not call your function repeatedly, and is much more expressive. The Play documentation has several related examples: http://www.playframework.org/documentation/2.0/JavaTemplates
If you absolutely need the index as well, try using Scala’s
zipWithIndex().