You can use the Visitor Validator;
You should add the <validator type="visitor">
snippet related to parts
object in your BookingAction-validation.xml
to activate the Visitor validation;
Then, you'll need to create an Part-validation.xml
under the package of the Part
Object (instead of the package of the Action
object), and specify there the rule for a single Part element.
Struts2 Validation Interceptor
will take care of validating each element of the List by using this second file.
As a nice side effect, if you include a List<Part>
object in another Action
, your validation for Part
object will be already there, with no need to rewrite it in another file (you will only need to declare the validator snippet in your Action-validation.xml file).
EDIT
You can specify different contexts for triggering a further, complementary validation of the same bean by using a more specific Bean-context-validation.xml
file, only in some specific cases.
Read this detailed example, especially the Visitor Validation Example
(and the following Visitor Validation with the Expression Validator
) part.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…