View Full Version : Problem with saving a date
jongraf
Apr 5th, 2006, 01:47 PM
I recently added a editable date field to a JSP. When I click submit to save the data, the page simply refreshes instead of continuing my flow. It does not even enter the action class. In an attempt to debug, I have the form using HTTP GET so I can see the URL being sent. If I remove the offending parameter representing the new date field, the submit processes normally.
In my domain, the field is of type java.util.Timestamp. Does anyone know of a compatibility issue? I am stumped and would appreciate any ideas to help debug this issue. I do not get any error messages.
epitoman
Apr 5th, 2006, 02:14 PM
Do you have a registered editorfor the Timestamp class, if not try to add an appropriate one in the initBinder method.
jongraf
Apr 5th, 2006, 02:16 PM
I added this from the birthDate sample, but it had no effect. I put it in the action class.
protected void initBinder(RequestContext context, DataBinder binder) {
// register a custom property editor to handle the date input
SimpleDateFormat dateFormat = new SimpleDateFormat("mm-dd-yyyy");
binder.registerCustomEditor(Timestamp.class, new CustomDateEditor(dateFormat, false));
}
epitoman
Apr 5th, 2006, 02:33 PM
I don't think you could use the CustomDateEditor out of the box as it creates java.util.Date which would not be suitable to your Timestamp property. I think you have to write your own Editor in this case
jongraf
Apr 5th, 2006, 02:37 PM
Ok I'm going to try to convert the Timestamp object to a Date object and see if that helps. I found that my bean definition for my form action was not pointing to my Action class but the superclass FormAction instead. I have it printing out a statement when it registers to the custom editor, so at least now I know it is getting that far. Thanks for your help, I'll let you know what happens when I convert it to a Date.
jongraf
Apr 5th, 2006, 02:43 PM
Thank you so much! You are correct about the CustomDateEditor. God I love Spring.
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.