I’m using Play! framework 20 on a java project and I have a problem with passing a form to the view.
In the controller I have the following code:
Filter filter = new Filter();
//add some state to the filter object
Form<Filter> filterForm = form(Filter.class).fill(filter);
Logger.info("FilterForm: " + filterForm.get().toString()); // So far so good
return ok(filterView.render(filterForm));
And in the template:
@filterForm.hasErrors() // renders false
@filterForm.data().isEmpty() // renders true!!
@* @filterForm.get().toString() *@ throws an Exception: No Value
I also get the same error if in the controller I fill the filter state via a Map:
filterForm = filterForm.bind(aMapWithTheState);
This behaviour is only when filling the filter in code. when I do filterForm.bindFromRequest() in other methods all works fine.
Thanks!!
Solved.
I had to use the form’s
bindmethod using a map with the state as I did before. But the correct way is to also pass the properties name:Despite that the documentation says that the property names are not mandatory.