views:

1107

answers:

2

Hi All, I am working on struts2 application. I have a jsp page having 3 textfields. And I am validating each field through action-validation.xml file. Now I want if validation get fail at first field it should not check the other two fileds and result directly go to jsp page (say a.jsp) showing error message for that single filed only. And if validation does not fail at first field then it should check rest of the fileds, i.e second and third fileld and now if validation fails here then also result directly go to jsp page but different one (say b.jsp) showing error message. Is it possible? If yes then please make me aware with this.

I have tried this but action-validation.xml is validating all fields in single shot and error messages for all fields is showing in a jsp page that I have written under a.jsp

Thanks in advance.

A: 

You can add a short-circuit in your field-validator

e.g.

<!-- 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 email is empty or not valid, email2 will not be validated

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

"Failure of a particular validator marked as short-circuit will prevent the evaluation of subsequent validators"

Roy Chan
Hi Roy,Its working fine. But I also want if email validation fails it will go to some jsp page (say a.jsp) and if email2 validation fails it will go to another jsp (say b.jsp). As it always return result as "input" when validation fails so i can target only one jsp page against it. Please provide solution if possible?Thanks for replying.
Vky, please close this as i've provided an answer to this question in http://stackoverflow.com/questions/828534/action-validation-xml-in-struts2-open-different-pages-when-validation-fails-at-d.
Rich Kroll
A: 

Hi, I also looking for this answer, have you solved it?