简体   繁体   English

没有错误的表单不返回任何值

[英]Form without errors returns no value

I have some problem with getting the value from the form object. 我从表单对象获取值存在一些问题。

  1. I'm handling the GET request. 我正在处理GET请求。 This generates form with predefined values: 这将生成具有预定义值的表单:

     Form<ModelObject> form = form(ModelObject.class).fill(new ModelObject()); return renderJapid(form); 
  2. In template I have defined parameter which takes Form<ModelObject> and it is named 'form'. 在模板中,我定义了采用Form<ModelObject>参数,并将其命名为“ form”。 On the page are only standard html input boxes like: 在页面上只有标准的html输入框,例如:

     <input type="text" id="fieldName" name="fieldName" value="$form.apply("fieldName").value()"> 
  3. After submitting this form I handle this POST request with another method: 提交此表单后,我可以使用另一种方法来处理POST请求:

     Form<ModelObject> form = form(ModelObject.class).bindFromRequest(); if (form.hasErrors()) { //render the form again with errors } else { ModelObject mo = form.get(); // NO-VALUE ERROR } 

    Each time I get no-value error on marked line where I want to get the object from form. 每次我要从表单中获取对象的标记行上都出现无值错误时。 Do you have any ideas where could be the problem? 您有什么想法可能出问题吗? (Pre-filled data are displayed and even the form object after submission has correct data but no-value) (显示预填充的数据,即使提交后的表单对象也具有正确的数据,但没有值)

Finnaly I solved my problem. 最终我解决了我的问题。 The problem was caused by my GenericModel class (each model class extends from this class) which has method public boolean validate() . 问题是由我的GenericModel类(每个模型类都从该类扩展)引起的,该类具有方法public boolean validate() When I removed this method everything worked fine. 当我删除此方法时,一切正常。 I know that this method is called by Play for my own custom validations on object, but I still don't understand why this changes the form value to None . 我知道Play会针对我自己的对象自定义验证调用此方法,但是我仍然不明白为什么这会将表单值更改为None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM