wood burning stoves 2.0*
The moose likes Struts and the fly likes date validation in struts 2 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 "date validation in struts 2" Watch "date validation in struts 2" New topic
Author

date validation in struts 2

mudassir shahab
Ranch Hand

Joined: Oct 13, 2003
Posts: 54
i want to compare two dates startDate and endDate . rules are defined in PersonAction-add-validation.xml ..the rest fields are doing fine .but date comparison is not working ...any idea how to compare that enddate should be greater than start date and also that both are mandatory ...n also do we need to define any date format ??..if yes ..how to define format..
Wes Wannemacher
Greenhorn

Joined: Jul 07, 2007
Posts: 13
This may be possible using the built-in validation, but I am not sure if I would trust it. You have to consider that you may have a user who uses a different format than you are hoping for... 2/1/2007 means Feb. 1, 2007 to me, but Jan. 2, 2007 to some. IIUC, Struts2 will attempt to make a "best guess" as to which date format the user will be entering, but IMO, that may not be enough. Whenever I've dealt with dates in the past, I'll make a set of dropdowns which name the month by their proper name, then a separate input for the day and a dropdown for the year. It is more work for the user entering the date, but it is cleaner for me to handle. If you were dealing with the dates as three separate input fields, you could fairly trivially create an expression that tests that the end date comes after the start date.

-W


Discussion of Java, Struts, Spring, Hibernate, etc. <a href="http://www.wantii.com" target="_blank" rel="nofollow">www.wantii.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date validation in struts 2
 
Similar Threads
inserting values in database after calculation
calcuate days in a calender.era or between two days
date format in struts 2
Date difference
DateFormat problem