简体   繁体   中英

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. 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'. On the page are only standard html input boxes like:

     <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:

     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() . 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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