File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts date vaidator problem

 
Mitesh K Patel
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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"/>
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yyyy</var-value>
</var>
</field>

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.

Thanx.
 
Ergin Er
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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 ?

Thanx,
Mitesh
 
Ergin Er
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic