java - Handling repeated values in template -
java - Handling repeated values in template -
the documentation says can utilize @repeat lists defined in forms.
http://www.playframework.com/documentation/2.1.0/javaformhelpers bottom of page.
this might totally stupid question... can utilize similar map?
right have helper class consist, string key , string value. works, have logic in template. in sentiment not good...
edit: more info
suppose have
class article { ... map<string, string> resources; ...getters, setters... }
i phone call view deal form
return ok(form.render(form.form(article.class)));
in form.scala.html
@for((key, value) <-formart("resources")) { @key, @value }
gives me error:
value map not fellow member of play.data.form.field
which makes finish sence, because not map anymore, formfield. there helper in scala deal list, have no thought how create helper deal map. (if seek similar, illustration utilize @repeat helper, gives me same error)
for asking in field.value
{value1=key1, value2=key2 ...}
if want iterate map can @defining()
, @for()
:
public static map<string, object> mymap() { map<string, object> mymap = new hashmap<>(); mymap.put("name", "john"); mymap.put("secondname", "doe"); mymap.put("age", 23); homecoming mymap; }
view:
@defining(application.mymap()) { mymap => hello @mymap.get("name") @mymap.get("secondname")! <br><br> entries of map: <br> @for(entry <- mymap.entryset()){ field <b>@entry.getkey()</b> has value: @entry.getvalue() <br> } }
java forms scala playframework-2.1
Comments
Post a Comment