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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 date conversion question" Watch "struts2 date conversion question" New topic

struts2 date conversion question

Marc Heruela
Ranch Hand

Joined: Jul 23, 2009
Posts: 38
Hello guys,

I would just like to ask how is a Date (in string) from a form is converted into java.util.Date object in struts2 by default.
I have noticed this strange behavaior, I have I timestamp/lastUpdated field displayed in the form (debugging purposes only),
when on submit the form failed the validation, the page will stay on the current page (with the form) with the unsaved data.
Now the problem is, the timestamp/lastmodified field value has been changed. Supposedly the field contains both the date and the time,
but now it only contains the date and the time was set to zero (the time part is dropped).

Now whenever I submit a valid form, my application will generate an error again:

This is because I implemented versioning/timestamping with my hibernate. The theory I have in mind is that when the object in my action class recieves
the value of the form, the timestamp/lastUpdate field was changed such that the time part of it was dropped, and when hibernate try to check the timestamp,
it failed because it is not anymore equal. And sure enough, when I tried to retrieve the timestamp / lastupdate field of the object to be saved before I invoke save
here are the values:

How do I prevent struts from dropping the time part of my timestamp field.
Is this really the default handling of struts with Date conversion (dropping time part), or have I done it incorrectly?

please advise

ps: I plan to create a custom converter for my timestamp/lastmodified field, by it is not working, I dont know what's the problem.

Marc Heruela
Ranch Hand

Joined: Jul 23, 2009
Posts: 38
Hello guys,

Mind sharing any inputs?


I agree. Here's the link:
subject: struts2 date conversion question
It's not a secret anymore!