Re: [2.0-java] Confusion on how validate model data

82 views
Skip to first unread message

James Roper

unread,
Oct 7, 2012, 9:42:05 PM10/7/12
to play-fr...@googlegroups.com
The Constraints.Required is part of the form validation API, and hence only works when validating forms.  However, you can easily tell the Form validation to validate JSON, like so:

Form<MyBean> myForm.bind(jsonData);

Will give you the validated MyBean, or the errors.

On Sunday, 7 October 2012 07:46:16 UTC+11, Mike wrote:
Apologies in advance if this is in the manual and I missed it or if it is somewhere in these forums.  I have searched around for a while now and I still can't seem to find what I am looking for.

I am trying to use the Constraints.Required on a model.  I was expecting these to be checked when I attempt to save the object but it appears my assumption was incorrect as my app is happily writing nulls for required columns.

I am not binding forms to the model, I am writing a web service and binding the Json using play.libs.Json.fromJson(jsonData,MyBean.class);  The only examples I see online are binding forms to models so I suspect that this may be the part I am missing but I am not certain.  If I wanted to have it validate on save, is that even possible and, if so, how?
Reply all
Reply to author
Forward
0 new messages