1

Is it possible in Struts 2 to avoid several validations (defined as anotations) depending on the value of a given field? Something like: "if radiobutton has value x do not validate fields a, b and c".

This would be useful to me since I'm developing a JSP page (model driven) and I'm not showing all the fields at the same time, the visible ones depend on a radiobutton value. However, when submiting, the validators from the hidden fields are "activated" and the validation process fails. So, I want to to ignore the hidden ones, is there a way to do this?

Thanks!

Paul Ulrich
  • 399
  • 1
  • 5
  • 13
  • I think this question has been asked before. See http://stackoverflow.com/questions/4553330/struts2-conditional-xml-validation or http://stackoverflow.com/questions/2329105/how-to-use-struts2-validation-for-conditional-validation – nmc Jul 21 '11 at 13:03

1 Answers1

0

I do this using OGNL and the expression validator Apache Struts 2 Documentation

I do this using xml because IMHO annotations are a bit intrusive, and rather not use them everywhere. But you sure can use the annotation version Validation Annotation.

Hope it helps...

megathor
  • 479
  • 3
  • 7
  • 1
    You should notice that the Validation annotation is deprecated since Struts2 2.1 and now you can use any other validation annotation at the method level without using it... – megathor Jul 21 '11 at 22:48