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 codepackage 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
)
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 supportpartial validation. No?And thank you very much for response and your advice about the _error field!