1600 PMP mock questions | 1400 CAPM mock questions | 800 SCJP 6 mock questions | 600 OCAJP 7 mock questions | 590 OCPJP 7 mock questions | 556 SCWCD 5 mock questions | 500 OCEJWCD 6 mock questions | pdfDownload (java,struts, hibernet etc) |
Java online test
JSP online test ORACLE online test Hibernate online test Servlet online test Struts online test EJB online test C online test C++ online test Aptitude online test |
Q. How to Setup validator framework in Struts ? |
|
Step 1.
place validator-rules.xml and validation.xml in the WEB-INF directory. Step 2. Add the blow lines to struts-config.xml <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/> </plug-in> Step 3. In the jsp add the tag <html:errors /> Step 4. Add struts.jar commons-beanutils.jar commons-collections.jar commons-digester.jar commons-fileupload.jar commons-lang.jar commons-logging.jar commons-validator.jar into WEB-INF/lib directory Explanation : There are two configuration files used. One if called validator-rules.xml and the other is validation.xml. This is example of server side validation : validator-rules.xml : The validator-rules.xml file defines the Validator definitions available for a given application. The validator-rules.xml file acts as a template, defining all of the possible Validators that are available to an application. Example validator-rules.xml File : <form-validation> <global> <validator name="required" classname="org.apache.struts.util.StrutsValidator" method="validateRequired" methodparams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.required"/> </global> </form-validation> validation.xml File : The validation.xml file is where you couple the individual Validators defined in the validator-rules.xml to components within your application. validation.xml File <form-validation> <formset> <form name="empForm"> <field property="firstName" depends="required"> <arg0 key="label.firstName"/> </field> <field property="lastName" depends="required"> <arg0 key="label.lastName"/> </field> </form> </formset> </form-validation> 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 label.firstName=First Name label.lastName=Last Name #Error messages used by the Validator errors.required={0} is required. Based on the validation.xml File configuration . Error in jsp will be : First Name is required. Last Name is required. {0} will be filled by (First Name or Last Name) because validation.xml above configuration you have defind <arg0 key="label.firstName"/>. |
||
Online Practice TestJava online testJSP online test ORACLE online test Hibernate online test Servlet online test Struts online test EJB online test C online test C++ online test Aptitude online test |
Reviews and Comments
PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc
Copyright © www.techfaq360.com 2019