Re: [2.1 master] Model validation @Constraints is not working (based on form sample)

219 views
Skip to first unread message

James Roper

unread,
Nov 14, 2012, 7:49:03 PM11/14/12
to play-fr...@googlegroups.com
You shouldn't need the '_error field, the defaultFieldConstructor renders the errors for you.  Can you show the action you are using to handle the form submission?

On Thursday, 15 November 2012 04:30:38 UTC+11, adel alfar wrote:
I created an @Entity Model class and decorated a field with @Constraints.Required.  I then submitted the form without filling the field.   The page rendered with no errors showing that the field was required.  I wonder what am I missing or if something had changed... Here is some code

package models;
...

@Entity

public class Driver extends Model {

public interface All {}

public interface Step1 {}

public interface Step2 {}

public User (

Long id

, String username

) {

this.id = id;

this.username = username;

}

@Id

public Long id;

@Constraints.Required

public String username;

@Constraints.Required

public String acceptedLicense;

}


template view:

 @inputText(

                signupForm("username"), 

                '_label -> "Username", 

                '_help -> "Please choose a valid username.",

                '_error -> signupForm("username").errors().mkString(", "),

                '_showConstraints -> false

            )

James Roper

unread,
Nov 15, 2012, 5:29:40 PM11/15/12
to play-fr...@googlegroups.com
We support partial validation?  I didn't know that :)  If you think you have found a bug, please raise it here:


On Friday, 16 November 2012 02:48:50 UTC+11, adel alfar wrote:
I actually found the error( on my part) , which was relating to the new 2.1 "Partial Validation" feature.   I had the following Action code (with the incorrect one commented):

 //final static Form<Driver> signupForm = form(User.class, User.All.class);

    final static Form<Driver> signupForm = form(User.class);

And since I did not specify the "groups=All.class" in the @Constraints.Require the Form did not bind correctly to the Model's validation errors.

So, in order to bind correctly (for the reader of this post) you need to specify the same  Partial Interface you specified in the Action/Form binding in the @Constraints.Required   annotation...

Speaking of which James:

For the @Constraints.Min(Max,Length) annotations...why aren't there partial validation support (via groups=) like in the Required annotation?
I think in order to be able to stack the @Constraints for a field with partial validation support, all Play Validation annotation should support
partial validation. No?

And thank you very much for response and your advice about the _error field!
Reply all
Reply to author
Forward
0 new messages