Hi Nathan,
This error usually happens when the form controller is not able to convert a
string representation of the object to the real object. Property editors are
used for this and spring doesn't support joda-time out of the box, so you
have to implement your own.
The error that you have says that the string "2008-12-02T00:00:00.000-08:00"
cannot be converted to a DateTime object. When you have a request spring
controllers do a lot magic behind the scenes such as data binding, and it is
here were the property editors are used.
Do you have a custom property editor for DateTime in the initBinder method?
You say you can save and update when you run "mvn jetty:run" check the
format of the string for the lastUpdated field, maybe is just a matter of
how the string is getting formatted in your test method.
I hope it helps,
Fabio
melinate wrote:
>
> Hi folks,
>
> I have an Appfuse 2.0.2 application with Spring MVC and iBatis. There is
> going to be a lot of date time math in this app, so I am trying to use
> Joda-Time for date fields in my POJO's. I figured out how to make iBatis
> convert the Timestamp to Joda's DateTime class. But I have one test that
> is
> failing and I'm not sure why and I'm hoping someone here can help.
>
> I have a POJO called "Client" with a DateTime property called
> "lastUpdated".
> I get an error when I run ClientFormControllerTest.testSave(), but I can
> create a new client or update an existing client when I run "mvn
> jetty:run".
>
> Here's the test method:
>
> public void testSave() throws Exception {
> MockHttpServletRequest request = newGet("/clientform.html");
> request.setRemoteUser("test");
> request.addParameter("id", "1");
>
> ModelAndView mv = controller.handleRequest(request, new
> MockHttpServletResponse());
>
> Client client = (Client)
> mv.getModel().get(controller.getCommandName());
> assertNotNull(client);
>
> request = newPost("/clientform.html");
> super.objectToRequestParameters(client, request);
> request.setRemoteUser("test");
> request.addParameter("name", "Updated Name");
>
> mv = controller.handleRequest(request, new
> MockHttpServletResponse());
>
> Errors errors = (Errors)
> mv.getModel().get(BindException.MODEL_KEY_PREFIX + "client");
> if (errors != null ) {
> log.error(errors.getAllErrors());
> }
>
> assertNull(errors); // <-- this assertion fails
>
>
> assertNotNull(request.getSession().getAttribute("successMessages"));
> }
>
>
> And the error message that is being returned:
>
> DEBUG - ClientFormControllerTest.testSave(48) | [Field error in object
> 'client' on field 'lastUpdated': rejected value
> [2008-12-02T00:00:00.000-08:00]; codes [t
> ypeMismatch.client.lastUpdated,typeMismatch.lastUpdated,typeMismatch.org.joda.time.DateTime,typeMismatch];
> arguments [org.springframework.context.support.Defaul
> tMessageSourceResolvable: codes [client.lastUpdated,lastUpdated];
> arguments
> []; default message [lastUpdated]]; default message [Failed to convert
> property valu
> e of type [java.lang.String] to required type [org.joda.time.DateTime] for
> property 'lastUpdated'; nested exception is
> java.lang.IllegalArgumentException: Canno
> t convert value of type [java.lang.String] to required type
> [org.joda.time.DateTime] for property 'lastUpdated': no matching editors
> or
> conversion strategy foun
> d]]
>
> Thanks for any help.
>
> Nathan
>
>
--
View this message in context:
http://www.nabble.com/Spring-MVC-test-failure-with-Joda-Time-tp20808213s2369p20837923.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]