0

I have a form having properties as a Map and I want to apply server side validations in struts2 for them.

How can I achieve this ?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Jagadeesh
  • 87
  • 1
  • 13

1 Answers1

0

If, instead of plain data, you are sending collections of data, you can't reference them directly in XML validation file (because you should hard-code an index, or a key, in your validators, and you can't obviously know it at compile time).

The solution is to use the Visitor Validator.

You specific a visitor validator in your yourAction-validation.xml, and you put a yourObject-validation.xml in the package of yourObject (not the one of yourAction, as you usually do), as described in this related answer.

That validator will be invoked for every element of your collection. I've used it for Lists, I'm not sure if it natively traverses Maps too. Just try, and let us know.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243