aspose file tools*
The moose likes Struts and the fly likes Date validation in struts.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Date validation in struts...." Watch "Date validation in struts...." New topic
Author

Date validation in struts....

Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
I have two date fields: Start date and End date and i want my start date to be lesser than end date. I want this to be done using validation.xml in struts. Can any body help me out in this!!!???!!!


Varsha
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Its "validwhen" type of validation I suggest you should first go thru this link:
http://struts.apache.org/1.3.10/faqs/validator.html#Designing_Complex_Validations_with_validwhen


And Welcome to JavaRanch
And no need to make it bold and green, its already a lot greeny out side my window, thanks to monsoon.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
Hey thanks a lot for your immediate reply...will check into it...

I use green coz its one of my favourite colors.......


Thanks,
Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
Hey,

I tried this code but its not working... could you please check if this is the right way to code.....or there is something else to be done in this case....!!!

<field property="startDate" depends="required,date,validwhen">
<var>
<var-name>datePatternStrict</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
<arg key="error.blank.startdate"/>
<var>
<var-name>test</var-name>
<var-value>((endDate > startDate) or (*this* == null))</var-value>
</var>
</field>

<field property="endDate" depends="required,date,validwhen">
<var>
<var-name>datePatternStrict</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
<arg key="error.blank.enddate"/>
<var>
<var-name>test</var-name>
<var-value>((endDate > startDate) or (*this* == null))</var-value>
</var>
</field>
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Please use CodeTags

And I may quick in first reply, but I understood this wouldn't solve your problem, because I suspect validwhen doesn't support "date" fields only string and primitive data type, still I correct an error for you



Try this code. Also if you want this validwhen approach, then you have break up the date field in three text boxes, like
[day] [month] [year] and then need to check the larger values in end date.

If it still fails then you have to write one plugbale validator for your own requirements, example:
http://raibledesigns.com/rd/date/20030226
Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
Thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Welcome
 
Consider Paul's rocket mass heater.
 
subject: Date validation in struts....