I'm using the Constraint annotations for validating my objects in Play! framework 2. It works fine for top level objects, but not nested ones. How do I get my nested object validation annotations to work?
Event: The top level object I am saving.
@Entity
public class Event {
@Required
public String name;
@OneToMany(cascade = CascadeType.ALL)
public List<Option> options;
...
}
Option: The nested object. Its not validating the name property.
@Entity
public class Option {
@Required
public String name;
...
}
Not familiar with Play, but it looks very close to javax.validation, in which you'd need to put @Valid
on your options
field to tell the validator to descend into that relationship. Play has an @Valid of its own, so I'd give that a shot.
Update: As OP pointed out, the above is Play 1.0. Instead, per the Play 2.0 docs, it uses Spring data binding and JSR-303 under the hood, so how about using the javax.validation @Valid annotation on it? Maybe Play 1.0 had a home-made validation framework and they decided to move to javax.validation in 2.0? That would explain why several validation annotations seem to have disappeared in the 2.0 API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With