This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 date conversion question" Watch "struts2 date conversion question" New topic
Author

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
-marckun

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.


-marckun
Marc Heruela
Ranch Hand

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

Mind sharing any inputs?

Thanks,

marckun
 
Consider Paul's rocket mass heater.
 
subject: struts2 date conversion question
 
Similar Threads
Converet from java.sql.Timestamp to java.util.Date
Struts2 Validation problem
Struts2 QUERY Regarding Built in Type Conversions in Struts2 Framework
ajax and struts2
get time information from oracle DATE field