Problem with multiple validation.xml for single action in struts2

I am working on struts2 application. I have a jsp page with 3 text boxes. And I validate each field with action-validation.xml file. Now I want to prevent the other two files from being checked when validating the validation in the first field, and the result goes directly to the jsp page (like a.jsp), showing an error message for only one registered one. And if the validation does not fail on the first field, then it should check the rest of the files, i.e. the second and third ld files, and now if the validation fails here, then also the result goes directly to the jsp page, but different (like b.jsp ) error message. Is it possible? If so, please let me know.

I tried this but action-validation.xml validates all fields in one shot and error messages for all fields in the jsp page I wrote under a.jsp

Thanks in advance.

0


source to share


1 answer


You can add short circuit to your field validator

eg.

<!-- Field Validators for email field -->
  <field name="email">
      <field-validator type="required" short-circuit="true">
          <message>You must enter a value for email.</message>
      </field-validator>
      <field-validator type="email" short-circuit="true">
          <message>Not a valid e-mail.</message>
      </field-validator>
  </field>
  <!-- Field Validators for email2 field -->
  <field name="email2">
     <field-validator type="required">
          <message>You must enter a value for email2.</message>
      </field-validator>
     <field-validator type="email">
          <message>Not a valid e-mail2.</message>
      </field-validator>
  </field>

      



if the email is empty or invalid, email2 will not be verified

http://struts.apache.org/2.x/docs/validation.html

"Failure of a specific validator marked as a short will prevent subsequent validators from being evaluated"

+1


source







All Articles