Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts sing validator framework work in struts
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Clark
sing validator framework work in struts
1 Answer(s)      3 years and 11 months ago
Posted in : Struts


How does client side validation using validator framework work in struts ?


Advertisement
View Answers

November 19, 2010 at 4:52 PM


Hi friends,

Struts provides two files for validation.
1 : validator-rules.xml
2 : validation.xml
with the help of this example, you can do client side validation.
Step 1.
Code of jsp page :

    `<html:form action="/bookSaveAaction" method="post" onsubmit="return validatebookForm(this);"`>

<html:text property="bookId" size="30" maxlength="30"/>
<html:text property="bookName" size="30" maxlength="30"/>

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

<!-- Start tag of  Validator Javascript Function-->
<html:javascript formName="empForm"/>
<!-- End tag of Validator Javascript Function-->
</html:form>
this tag is used for client side validation.

Step 2.
struts-config.xml is cofiguration file. It is used for action mapping

<action
path="/bookSaveAaction"
type="bookForm"
name="AddressForm"
scope="request"
validate="true"
input="/bookform.jsp">
<forward name="success" path="/success.jsp"/>
</action>

<form-beans>
<form-bean name="bookForm" type="com.roseindia.form.bookForm" />
</form-beans>

Step 3. validator-rules.xml :

The validation definitions available for given application is defined by the validator-rules.xml files. The validator-rules.xml file acts as a template, defining all of the possible Validators that are available to an application.

validator-rules.xml File :

</global>
</form-validation>

    <validator name="required"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateRequired"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       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="bookForm">
<field
property="bookId"
depends="required">
<arg key="label.bookId"/>
</field>

<field
property="bookName"
depends="required">
<arg key="label.bookName"/>
</field>
</form>
</formset>
</form-validation>

The bookId and bookName are the required filed of the bookForm . So in the above configuration you can see we add for both bookId and bookName.

You can see depends="required" - "required" property is defind in validator-rules.xml.

In the resource bundle : application_resource.propertis file
label.bookId=bookId
label.bookName=bookName
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.
bookId is required.
bookName is required.

Thanks.



Related Tutorials/Questions & Answers:
sing validator framework work in struts
sing validator framework work in struts  How does client side validation using validator framework work in struts
validator framework work in Struts
validator framework work in Struts  How does validator framework work in Struts
Advertisements
Setup validator framework in Struts
Setup validator framework in Struts  How to Setup validator framework in Struts
Struts Validator Framework
Struts Validator Framework  What is Struts Validator Framework
Using the Validator framework in struts
Using the Validator framework in struts   What is the Benefits of Using the Validator framework in struts
Struts Validator Framework
Struts Validator Framework     ... Framework. In this lesson you will learn how to use Struts Validator Framework... to Validator Framework Struts Framework provides the functionality to validate the form
Fixed Value check using struts validator framework
Fixed Value check using struts validator framework  Hi All, can anyone tell me how to use struts validator framework for fixed value check. eg. country='India'; Thanks in advance
Struts Validator Framework - lab oriented lesson
STRUTS-VALIDATOR FRAMEWORK R.S.Ramaswamy ( developeriq..Oct-2005... framework.In this first part, a simple struts demo with non-framework based... of Validator framework, with a lab-oriented lesson. Since its introduction in 2001
XML files used in Validator Framework?
XML files used in Validator Framework?  Give the Details of XML files used in Validator Framework
Struts 2 double validator
Struts 2 double validator       The Double validator of Struts 2 Framework checks if the given input is double... validator can also be used to check the input range. This example is a demonstration
Struts 2 Date Validator
Struts 2 Date Validator       The Date validator in the Struts 2 Framework checks whether the supplied date lies... demonstrates how to use the date validator to check the input range. [ NOTE: If date
USING THE VALIDATOR FRAMEWORK
STRUTS-VALIDATOR FRAMEWORK USING THE VALIDATOR FRAMEWORK       Validator framework requires two XML files, namely, alidator... and struts-config.xml. So, no special installation is necessary, to use the Validator
Struts 2 E-mail Validator
Struts 2 E-mail Validator       The email validator in  Struts 2 Framework checks whether a given String... value does not match with the email type then the e-mail validator generates
Struts 2 RequiredString validator
Struts 2 RequiredString validator       This section discusses RequiredString validator of Struts 2 framework... the forms, required String validator will generate error message
validation using validator-rules.xml - Struts
validation using validator-rules.xml  Hi I am trying to validate my form using Validator-rules.xml. I am using Eclipse 3.0 Struts 1.1 and Tomcat.../struts/struts_validator_framework.shtml Thanks
URL Regular Expression for Struts Validator
URL Regular Expression for Struts Validator  I want to know how to validate a url link in struts validation.xml. Please share me the regular expression for url link validation
URL Regular Expression for Struts Validator
URL Regular Expression for Struts Validator  I want to know how to validate a url link in struts validation.xml. Please share me the regular expression for url link validation
Struts - Framework
it is better to go for Struts or any other framework. While if you are working... then it is not necessary to use struts or any other framework. Although various MVC frameworks are being used in production, but Struts is the most popular framework than
Struts validation not work properly - Struts
Struts validation not work properly  hi... i have a problem with my struts validation framework. i using struts 1.0... i have 2 page which...) { this.address = address; } } my struts-config.xml
Struts - Framework
, Struts : Struts Frame work is the implementation of Model-View-Controller... project and is open source. Struts Framework is suited for the application... struts application ? Before that what kind of things necessary
Struts Tutorial
, struts integration with other framework, Struts Validator Framework. What is Struts ? Struts is an open source MVC based framework for developing web..., internationalization, error handling, tiles layout etc. Struts framework is also
struts - Framework
struts  can show some example framework of struts  Hi Friend, Please visit the following links: http://www.roseindia.net/struts/ http://www.roseindia.net/struts/struts2/ Hope that the above links
Struts - Framework
in any other framework or else before starting struts. you just need to have... struts application ? Before that what kind of things necessary... that you are going to learn Struts. Just refer "http://www.roseindia.net
Struts 2 Validation (Int Validator)
of Struts 2 framework: Conversion Validator Date Validator Double...Struts 2 Validation (Int Validator)       Struts 2 Framework provides in-built validation functions to validate user
struts - Framework
Struts design pattern  Please explain Struts design pattern
struts - Framework
Struts Spring Hibernate Integration  struts spring hibernate integration tutorial
struts - Framework
struts  Tag libs in struts
struts - Framework
be defined in the Commons Validator configuration when dynamicJavascript="true
struts - Framework
Struts flow of execution diagram  What is the structure of struts flow ..can you show it with the help of diagram
Struts framework
Struts framework  How to populate the value in textbox of one JSP page from listbox of another JSP page using Struts-html tag and java script
Struts framework
Struts framework  How to populate the value in textbox of one JSP page from listbox of another JSP page using Struts-html tag and java script
 

 

 

DMCA.com