I want to validate a domain object without automatic parameter binding to restrict the properties that can be set by the client.
The following class (example from Play! docs) …
public class User {
@Required
public String name;
@Required
@Min(0)
public Integer age;
}
… is usually validated like this
public static void hello(@Valid User user) {
if(validation.hasErrors()) {
params.flash();
validation.keep();
index();
}
render(user);
}
But in this scenario all fields of user can be set by the client.
Is it possible to trigger domain object validation (not “controller validation”) with Play! 1.2 explicitly?
public static void hello(long id, String name) {
User user = User.findById(id);
user.name = name;
user.validate(); // <-- I miss something like this
if(validation.hasErrors()) {
params.flash();
validation.keep();
index();
}
render(user);
}
Have you tried