Tutorial Home
Hibernate
StrutsJSP
Spring
|
Struts Tutorial -- Code ExamplesValidation Framework-Client Side
Validation Framework provides the functionality to validate the form data. It can be use to validate the data on the client side. Errors will be displayed like java script. Follow the below steps to setup Validation Framework in Struts (server side validation ). Step 1. Add validator plugin into struts-config.xml
Step 3. In the JSP page (EmpForm.jsp)- Add onsubmit="return validateempForm(this);" and <html:javascript formName="empForm"/> for Client Side Java Script Validation.
Step 4. Add Message Resources location in struts-config.xml
Step 5. In the the Resource Bundle. application_resource.properties file //Here you can add localization.
Step 7. In the EmpForm
Step 6. In the validation.xml - The validation.xml file is where you couple the individual Validators defined in the validator-rules.xml to components within your application
Step 6. In the validator-rules.xml - The validator-rules.xml file defines the Validator definitions available for a given application.
Step 5. Add Action mapping and form entry into the stuts-confix.xml and validate="true" is for validation framework to validate the form input.
Now in the browser type http://localhost:8080/testApp/EmpForm.jsp
Don't Enter firstName and lastName in the text box and submit the "Save" BUTTON.
the RequestProcessor checks for the validateattribute in the
ActionMapping. First Name is required.
In the empForm firstName and lastName are the required filed.
So in the above configuration you can see we add for both firstName and lastName.
You can see depends="required" - "required" property is defind in validator-rules.xml.
In the resource bundle : application_resource.propertis file |