Question

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)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top