91-9990449935 0120-4256464 |
Struts 2 Ajax Validation - jsonValidation InterceptorStruts 2 provides support to ajax validation. In such case, page will not be refreshed or reloaded so it will make the performance fast. It is implicitly done using javascript i.e. used for the client side validation. To use the AJAX validation, you need to add dojo plugin in your project.jsonValidation InterceptorThe AJAX validation is performed by jsonValidation interceptor. It is not found in the default stack so we need to define it explicitly. It doesn't perform any validation itself that is why it must be used with validation interceptor. It is found in the jsonValidationWorkflowStack, that includes jsonValidation, validation and workflow interceptors and basicstack. Steps to perform AJAX ValidationThe simple steps to perform AJAX Validation are as follows:
Example to perform ajax validationIn this example, we are creating 4 pages :
1) Create index.jsp for inputThis jsp page creates a form using struts UI tags. It receives name, password and email id from the user. index.jsp2) Create the action classThis action class inherits the ActionSupport class and overrides the execute method. RegisterAction.java3) Create the validation fileHere, we are using bundled validators to perform the validation. Register-validation.xml4) Create struts.xmlThis xml file defines an extra result by the name input, and an interceptor jsonValidatorWorkflowStack. struts.xml5) Create view componentIt is the simple jsp file displaying the information of the user. welcome.jsp
Next TopicStruts2 Aware Interfaces Tutorial
|