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

Reply via email to