File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "date validation in struts 2" Watch "date validation in struts 2" New topic

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 to define format..
Wes Wannemacher

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.


Discussion of Java, Struts, Spring, Hibernate, etc. <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: date validation in struts 2
It's not a secret anymore!