vendredi 20 février 2015

Conditional Validation in Java



I am trying to do bean validation in a Object graph. Lets say I have two classes called Foo and Bar. They have @OneToOne relationship.


Foo.class



class Foo
{
String a;
String b;
boolean c;

@Valid
Bar bar;
}


Bar.class



class Bar
{
String i;
String j;
String k;
String l;
}


I want to validate Both Foo and Bar but I want to do conditional validation on Bar depending on the value entered in Foo.class. Depending on the value of c in Foo.class, I want to validate the fields in Bar.class. If c is true, then I want to validate i and j. If c is false then I want to validate k and l.


Is there anyway I can do it?




Aucun commentaire:

Enregistrer un commentaire