-
How do I dynamically render HTML in Play? For example I have an enum or DB table with a list of platforms (pc/xbox/ps3). I want to render in my HTML form a checkbox list with each of those. For now I’ve just hard coded the HTML form with elements, but long term it needs to be dynamic and the lists (checkbox/radio/dropdown) need to be bound to the system so they receive new items as new items are added to the database.
-
On postback how do i access those form fields in the controller handling the postback? I’ve found that in the controller action’s function parameter list I can specify the name of the form field, and that works, but this is unrealistic if i’m going to have forms that have 100 fields, then I do’nt want to have to declare 100 params in my controller action function.
How do I dynamically render HTML in Play? For example I have an enum
Share
you can call method
values()on enums to obtain array of enum values. And then map it to List. For example you can useLists.newArrayList(array)from google-collections.form parameters you can find in
request.paramshashmap. Request is a field inherited from play.mvc.Controller.Also have a look at this http://www.playframework.org/documentation/1.2.3/cheatsheet/controllers. (Usefull stuff but not easy to find)
UPD
List theList =....;render(theList);and in the template (example for select):