Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Struts Struts 2 Example Tutorial >>> Struts1 date validation >>> Example Code Discussed
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : guddu
Title :
Struts Eclipse MVC
Description : Step by step demonstration
More...


Written By : Girish
Title :
Struts Tiles I18N Example
Description : Code with Sample Action
More...


Written By : ISHTEK
Title :
Struts2 questions
Description : open for discussion
More...


Written By : ISHTEK
Title :
Struts2 Tiles Example
Description : with Code and article
More...


Written By : ISHTEK
Title :
Struts2 Tiles I18N Example
Description : with code explained article
More...


Written By : Amit
Title :
Struts2 Tag Library Example
Description : Tutorial
More...


Written By : Amit
Title :
Struts2 Tags Example
Description : Code and Tutorial
More...


Written By : Amit
Title :
Radio Tag Example
Description : Step By Step Code
More...

Tags/Keywords : Struts, Struts2 Tutorial, Struts 2 Example, Struts2
Author : admin
Date (Year/Month/Date): 2010-05-31 Struts 1.x version and date validation example discussed

Please be informed that NONE of the design/code/matter from this page is claiming to be some
sort of best practice and we DO NOT expect any of our visitor/reader of this page to assume
this as some sort of best practice for any context and should not be using this as it is
without appropriate evaluation.
This page intends only to provide bits and pieces of known ways  for doing some sort of example
and may not be fit for any other purpose.

In spite of all precautions taken to provide accurate and avoid any typo in these pages,
there might be some issues like grammatical mistakes and typo being observed in these pages,
We extend our sincerest apologies for the same.


Date validation can be performed using validator framework while using Apache Struts 1.x version. I have successfully executed following example with a very simple date validation for required and date pattern and date pattern strict. One of the difference between datePattern and datePatternStrict is with datePattern only the pattern is matched and not the total length and whether a valid date or not a date is validated. While datePatternStrict is used to check for valid date and total length of the field value as well. This example is having a very simple date field and the corresponding validation XML file is as follows: --------------------------------------------------------- <form-validation> <global> </global> <formset> <form name="exampleForm"> <field property="name" depends="required,mask"> <arg0 key="exampleForm.name.text"/> <var> <var-name>mask</var-name> <var-value>^[a-zA-Z]+$</var-value> </var> </field> <field property="dob" depends="required,date"> <arg0 key="exampleForm.dob.text"/> <var> <var-name>datePatternStrict</var-name> <var-value>mm - dd - yyyy</var-value> </var> </field> </form> </formset> </form-validation> --------------------------------------------------------- so the actionform is defined as exampleForm in the struts-config.xml file: --------------------------------------------------------- <form-bean name="exampleForm" type="action.ExampleForm"/> --------------------------------------------------------- index.jsp file is as follows: --------------------------------------------------------- <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <html:html locale="true"> <head> <title><bean:message key="index.title.label"/></title> <html:base/> </head> <body bgcolor="white"> <logic:messagesPresent> <html:messages id="errors"> <%= errors %> </html:messages> </logic:messagesPresent> <table> <html:form method="post" action="example"> <tr><td><bean:message key="index.name.label"/> </td><td><html:text property="name"/></td> </tr> <tr><td><bean:message key="index.dob.label"/></td> <td><html:text property="dob" /></td> </tr> <tr><td><html:submit property="butSubmit" value="Submit"/></td> <td><html:button property="butReset" value="Reset"/></td> </tr> </html:form> </table> </body> </html:html> --------------------------------------------------------- Following the above JSP file, the action mapping in struts-config XML file is as follows: --------------------------------------------------------- <action-mappings> <action path="/example" type="action.ExampleAction" name="exampleForm" scope="request" validate="true" input="/index.jsp"> <forward name="success" path="/preview.jsp"/> </action> </action-mappings> --------------------------------------------------------- and the next file is a preview page, which can be a very simple page witha println statement only, just to know that this page is called after successful validation happening. Hope this helps. If you have any further queries and need to discuss please write to me here in this page.


	
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
22,18
Enter bigger number from above :*
Home >>> Struts Struts 2 Example Tutorial >>> Struts1 date validation >>> Example Code Discussed
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
27,35
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
 

Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners

This web site's Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
or imply reliability of these example source code or programs.

By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
at contact.