Client Side validation in Struts 2 application

Advertisement

In this section we will see how to write code that will generate Java Script code for client side validation. In the last section we developed Login-validator.xml configuration file for defining the server side validation. In this section we will use the

Client Side validation in Struts 2 application

In this section we will see how to write code that will
generate Java Script code for client side validation. In the last section we
developed Login-validator.xml configuration file for defining the server side
validation. In this section we will use the same Login-validator.xml file for
generating the client side java script.

Note that in the above code we have just added
validate="true"in
the <s:form tag...>. This is the only work we have to do and rest work is
done by Struts 2 validator framework. The validator framework generates
JavaScript for validating the form at client side.

Nikhil
April 22, 2011
Not working
Could you please send me the working source code? Its not working. I tried your code too.
Do we need to choose some special theme for it?
Thanks

k k sathish kumar
November 22, 2011
This will not work correct in some scenario.
In my application I tried this when I call an action class's method from an anchor tag. The method that called will fetch data from DB and fill my form field such as drop down list in the next page. when I run the application it validates the page while the page gets loaded. but actually it should validate when I give submit.