2

I am facing the issue in Struts2 validation.

My Action class is NotificationsAction

My Model class is UserNotificationsForm .

I have created the NotificationsAction-validation.xml

<validators>         
    <field name="userNotificationForm">
        <field-validator type="visitor">
            <param name="appendPrefix">false</param>
            <message/>
        </field-validator>
    </field>

and UserNotificationsForm-notifications_update-validation.xml is

<field name="userNotificationForm.email">
    <field-validator type="requiredstring">
        <message key="register.validation.email" />
    </field-validator>
    <field-validator type="email-custom">
        <message key="register.validation.email.format" />
    </field-validator>
</field>

When i am inserting the wrong email it is not validating properly

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Not clear where your visitor validation filename comes from. Is `notifications_update` your method ? Not sure you can use visitor like that. Try renaming it to `UserNotificationsForm-validation.xml`, and ensure it is on the same path of `UserNotificationsForm`, NOT the action's path. – Andrea Ligios Feb 18 '14 at 14:24
  • notifications_update is a method. UserNotificationsForm-validation.xml i tried this way also not getting any luck – user3239669 Feb 18 '14 at 14:29
  • It must be the name of the Java class, not the instance. Is it ? And is it in the path I asked you to verify ? – Andrea Ligios Feb 18 '14 at 14:37
  • Does email-custom works ? – Andrea Ligios Feb 18 '14 at 14:37
  • yes email-custom is working fine. path is same for UserNotificationsForm and UserNotificationsForm-notifications_update-validation.xml – user3239669 Feb 18 '14 at 14:41
  • when i put the correct email in form then action's method is executed , in case of wrong email method is not invoke – user3239669 Feb 18 '14 at 14:42
  • LOL ! That's the normal behavior ! If the validation fails, it will return INPUT ***before*** reaching the Action method. Configure INPUT result and `` and you will see. This is different from "it is not validating prperly". [Read more on this](http://stackoverflow.com/a/13379721/1654265) – Andrea Ligios Feb 18 '14 at 14:53
  • but in other case action method are invoked and in that method we check the ArrayList errorList = doGenericValidation();. – user3239669 Feb 18 '14 at 15:05
  • sorry may be i am doing some silly mistake because its working fine this way in my project. – user3239669 Feb 18 '14 at 15:06

0 Answers0