1
我一直無法讓表單綁定正常工作(基本上是試用版和錯誤)。 In Play 2.0.3(Java)將表單綁定到由其他對象組成的模型的正確方法是什麼?如何將表單字段綁定到Play 2框架中的對象
我捏造了這個小例子,試圖更好地理解它。 但即使這個基本的例子似乎有問題。
我試圖綁定窗體的簡單類有3個字段一個純字符串字段,一個字符串列表和一個自定義字段,它只是一個字符串包裝。 在提交表單之後,除了保留爲空的自定義字段外,所有字段都會填充。
下面是實際的代碼
控制器
static Form<Simple> simpleform=form(Simple.class);
public static Result simpleForm(){
Form<Simple> filledForm=simpleform.bindFromRequest();
System.out.println(filledForm);
return ok(views.html.simpleForm.render(filledForm.get().toString()));
}
型號
查看
@(text:String)
@import helper._
@form(routes.Management.simpleForm()){
<input type="hidden" value="string" name="stringList[0]">
<input type="hidden" value="stringAgain" name="stringList[1]">
<input type="hidden" value="wrapped" name="wrappedText.otherText">
<input type="text" id="text" name="text">
<input type="submit" value="submit">
}
This was passed @text