File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes struts date vaidator problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts date vaidator problem" Watch "struts date vaidator problem" New topic

struts date vaidator problem

Mitesh K Patel

Joined: Nov 24, 2005
Posts: 3

I have been using struts inbuilt validation framework for my application.

i m using it to validate date format in 'dd/MM/yyyy'

in my validation.xml file,
<field property="fromDate" depends="date">
<arg key="testReportBean.fromDate"/>

i want date like '1/1/2006' as a valid date. Dont want user to strictly input '01/01/2006'. the above scriptlet strictly want the date entered with leading zeros.

In all the material available on internet, i hv read tht if var-name is 'datePattern' then it should not validate strictly for the date with leading zeros.
But its not working for me.

Can any one pls help me on this issue.

Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
I don't get it. If you define the pattern to be dd/MM/yyyy, then you can't blame the validator to expect leading zeros conform to the pattern. Making the leads optional sounds more like "regex" to me.
The only date validation within validator framework I can find is "isDate" that checks if the date is valid.
Mitesh K Patel

Joined: Nov 24, 2005
Posts: 3

In my application user is also allowed to input date, and i do not want use to enter date in strict format.

And in struts validation framework, there are two variable available ,

if i use datePatternStrict, then only it should check for perfect date format with leading zero.

if i use datePattern, then it should allow date like, 1/11/2006, and should not give error message,

But still 'datePattern' is not working.

Is there any problem with version of struts jar file ?

Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
by the way: the dependency date that you're using and the variable datePattern don't seem to be in sync. Maybe you should try changing depend=date to depend=datePattern
Marwin kovarex

Joined: Dec 15, 2005
Posts: 1
I have the same problem with validator, validation routines are written in way, that doesn't accept formates like d.M.yyyy(it looks for "dd" "MM" in the javascript cod), and changing datePatterStrict to datePattern, which should make the thing doesn't help too.
Is somewhere some corrected validateDate function, that i could replace?
subject: struts date vaidator problem
Similar Threads
Date Validator scrolls the date
struts validation
Date Formatting Problem with Validator
Required field usage
future date validation