Java – validation does not apply to nested objects in play framework 2

I'm using constraint annotation to verify the objects in play! Frame 2 It applies to top - level objects, but not nested objects How do I make nested object validation comments effective?

Event: top level object I am saving

@Entity
public class Event {

    @required
    public String name;

    @OneToMany(cascade = CascadeType.ALL)
    public List<Option> options;

    ...
}

Options: nested objects It has no validation name attribute

@Entity
public class Option {

    @required
    public String name;

    ...
}

Solution

I'm not familiar with play, but it looks very close to javax Validation, you need to put @ valid on your option field to tell the verifier to enter the relationship Play has its own @ valid, so I'll give it a shot

Update: as OP pointed out, the above is play 1.0 On the contrary, according to play 2.0 docs, which uses spring data binding and jsr-303, how to use javax What about the validation @ valid annotation? Maybe play 1.0 has a self-made verification framework, and they decided to turn to javax in 2.0 validation? This explains why several validation comments seem to have disappeared in the 2.0 API

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>