Search code examples
javavalidationstruts2dtdxml

Struts 2.5 Update Action Validator Issue (Conditional Validation)


I have included the updated validator DTD, meaning that I changed the declaration from

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

to

<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
                        "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">

My problem is the following: I have a dropdown of option A and B - selecting option A results in input fields being displayed, meaning, fields that I wish to validate with the above-mentioned validator. However, selecting option B does not require the validation of those fields because they are made to only show up for option A. This is where the action fails and does not redirect me to the next action. In the old version of Struts, this worked fine, but now, even though I don't wish to validate the fields while option B is selected, it still seems to attempt validating them, and them being blank, fails to continue. It doesn't throw a specific error. I tried selecting Option A first, filling in the fields, then Option B, and that succeeds.

How do I stop Struts from using the validators when option B is selected?


Solution

  • You can change the action on change event when you select an option.

    One action is configured to use validation interceptor, but another is not invokes validation or you put @SkipValidation annotation on the action method.