我一直有麻烦我的表单绑定正确(基本上试错)工作。 在播放2.0.3(JAVA)是什么将窗体绑定到它是由其他对象的模型的正确方法?
我做了这个小例子,试图更好地理解它。 但是,即使这个简单的例子似乎有问题。
这我想表单绑定的简单类有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()));
}
模型
public class Simple {
public String text;
public List<String> stringList;
public SimpleWrapper wrappedText;
@Override
public String toString(){
return text +"-"+simpleWrapper+"-"+stringList;
}
public class SimpleWrapper{
String otherText;
public SimpleWrapper(){}
public SimpleWrapper(String otherText){
this.otherText=otherText;
}
@Override
public String toString(){
return otherText;
}
}
视图
@(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