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 does client side validation using validator framework work in struts ?

There are two configuration files used.
One if called validator-rules.xml and the other is validation.xml.
This is example of client side validation :Java Script message.

Step 1.
In the JSP page : empform.jsp
<html:form action="/EmpSaveAaction" method="post" onsubmit="return validateEmpForm(this);">

<html:text property="firstName" size="30" maxlength="30"/>
<html:text property="lastName" size="30" maxlength="30"/>

<html:submit>Save</html:submit>

<!-- Begin Validator Javascript Function-->
<html:javascript formName="empForm"/>
<!-- End of Validator Javascript Function-->
</html:form>


You have to add
<html:javascript formName="empForm"/> in JSP for activate client side validation .

Step 2.
Add action mapping in struts-config.xml

<action
path="/EmpSaveAaction"
type="empForm"
name="AddressForm"
scope="request"
validate="true"
input="/empform.jsp">
<forward name="success" path="/success.jsp"/>
</action>

and add the form bean inside <form-beans> </form-beans> tag
<form-beans>
<form-bean name="empForm" type="com.techfaq.form.EmpForm" />
</form-beans>


Step 3.
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>

Step 4.
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">
<arg key="label.firstName"/>
</field>

<field
property="lastName"
depends="required">
<arg 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 : Java Script message.
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 <arg key="label.firstName"/>.

Online Practice Test

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

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy