PDA

View Full Version : CustomDateEditor problems with Spring 1.1



telcontar4
Sep 8th, 2004, 03:07 PM
After upgrading from v1.0.2 to v1.1 yesterday, I have encountered a problem with the CustomDateEditor. Essentially, it neither formats the java.util.Date property in my INPUT field (it displays using the default date format) nor recognizes dates of any format when submitting the form (the property value is null, thus generating a validation error). This all worked fine in 1.0.2.

Excerpt from JSP


<form method="post">
...other fields...

<label>
Order Date
<spring&#58;bind path="order.orderDate">
<input type="text" class="text-medium"
name="<c&#58;out value="$&#123;status.expression&#125;"/>"
value="<c&#58;out value="$&#123;status.value&#125;"/>">
<span class="error"><c&#58;out value="$&#123;status.errorMessage&#125;"/></span>
</spring&#58;bind>
</label>

<input type="submit" class="button" value="Save"/>
</form>


Excerpt from AbstractWizardFormController subclass


protected void initBinder&#40;HttpServletRequest request,ServletRequestDataBinder binder&#41; throws Exception &#123;
super.initBinder&#40;request, binder&#41;;

DateFormat dateFormat = DateFormat.getDateInstance&#40;DateFormat.SHORT&#41;;
binder.registerCustomEditor&#40;Order.class, "orderDate", new CustomDateEditor&#40;dateFormat, true&#41;&#41;;

...registration of other custom PropertyEditors that work fine...
&#125;


I looked in the changelog.txt and on this forum, but could not see anything to suggest why this code no longer works. Can anyone help me out?

Thanks,

Alef Arendsen
Sep 9th, 2004, 08:37 AM
Excerpt from AbstractWizardFormController subclass


protected void initBinder&#40;HttpServletRequest request,ServletRequestDataBinder binder&#41; throws Exception &#123;
super.initBinder&#40;request, binder&#41;;

DateFormat dateFormat = DateFormat.getDateInstance&#40;DateFormat.SHORT&#41;;
binder.registerCustomEditor&#40;&#91;b&#93;Order.class&#91;/b&#93;, "orderDate", new CustomDateEditor&#40;dateFormat, true&#41;&#41;;

...registration of other custom PropertyEditors that work fine...
&#125;




Order.class should be changed to Date.clas. It should be the property you want the String to be resolved to, not the command class. Maybe the checking mechanisms changed a bit in 1.1.

telcontar4
Sep 10th, 2004, 09:36 AM
Alef,

That makes sense (and works)! I'm curious as to why the old code worked in 1.0.2, but it definitely seems correct the way it works in 1.1.

Thanks!

Alef Arendsen
Sep 14th, 2004, 09:15 AM
I browsed along the revision history of the BeanWrapper and its collaborators when I tested this but couldn't find anything real quickly. So I guess it'll be a mystery for ever ;-)