Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:16:11+00:00 2026-05-31T02:16:11+00:00

I am facing a weird problem right now with JodaTime DateTimes and a Spring

  • 0

I am facing a weird problem right now with JodaTime DateTimes and a Spring MVC controller. Although I see that the InitBinder-annotated method is invoked, it is without effects, the strings of the test request are not bound to my domain object, as can state the following error message:

org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'eventCommand' on field 'endDate': rejected value [29/03/2015 12:13]; codes      [typeMismatch.eventCommand.endDate,typeMismatch.endDate,typeMismatch.org.joda.time.DateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [eventCommand.endDate,endDate]; arguments []; default message [endDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'endDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull @javax.persistence.Column @org.hibernate.annotations.Type org.joda.time.DateTime for value '29/03/2015 12:13'; nested exception is java.lang.IllegalArgumentException: Invalid format: "29/03/2015 12:13" is too short]
Field error in object 'eventCommand' on field 'startDate': rejected value [28/03/2015 12:13]; codes [typeMismatch.eventCommand.startDate,typeMismatch.startDate,typeMismatch.org.joda.time.DateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [eventCommand.startDate,startDate]; arguments []; default message [startDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'startDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull @javax.persistence.Column @org.hibernate.annotations.Type org.joda.time.DateTime for value '28/03/2015 12:13'; nested exception is java.lang.IllegalArgumentException: Invalid format: "28/03/2015 12:13" is too short]

Here is the meaningful part of the controller:

@Controller
@RequestMapping("/***/event")
public class EventController {

    private static final String COMMAND = "eventCommand";
    @Autowired
    private EventDao eventDao;

    @InitBinder(value = COMMAND)
    public void customizeConversions(WebDataBinder binder) {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        df.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
    }

    @RequestMapping(value = {
            "/new",
            "/edit/{id}"
    }, method = POST)
    public ModelAndView save(@ModelAttribute(COMMAND) @Valid final Event event, final BindingResult result) {
        if (result.hasErrors()) {
            return populatedEventForm(event);
        }
        eventDao.saveOrUpdate(event);
        return successfulRedirectionView();
    }

    private ModelAndView successfulRedirectionView() {
        return new ModelAndView("redirect:index.jsp");
    }

    private ModelAndView populatedEventForm(final Event event) {
        ModelMap model = new ModelMap(COMMAND, event);
        return new ModelAndView("event/form.jsp", model);
    }
}

As well as the test request (driven by spring-test-mvc):

@Test
public void when_saving_valid_event_then_routed_to_home() throws Exception {
    mvc.perform(post("/***/event/new").
            param("title", "zuper title").
            param("description", "zuper description").
            param("startDate", "28/03/2015 12:13").
            param("endDate", "29/03/2015 12:13")).
            andExpect(status().isOk()).
            andExpect(view().name("redirect:index.jsp"));
}

And the entity:

@Entity
public class Event {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id")
    private long id;
    @NotBlank
    @Length(max = 1000)
    @Column(name = "description", nullable = false)
    private String description = "";
    @NotNull
    @Column(name = "start_date", nullable = false)
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime startDate;
    @NotNull
    @Column(name = "end_date", nullable = false)
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime endDate;
    @NotBlank
    @Length(max = 255)
    @Column(name = "title", nullable = false, unique = true)
    private String title = "";

    /* setters & getters */
}

If I commit the @InitBinder-annotated method, the result is the same…
I’ve got the same kind of data binding for another entity (with 1 DateTime member) and it works fine.

Any idea what is wrong ?

Thanks in advance,

Rolf

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:16:13+00:00Added an answer on May 31, 2026 at 2:16 am

    Alright I found the problem, I was exposing my properties directly as DateTime and not as Date as I was doing for my other entity.

    Exposing Dates did the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing this weird problem. The WebApp I'm debugging right now, is invoking
In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I
I'm facing a strange problem right now... I'm trying to use Facebook API to
I'm new to jQuery and am facing now a weird problem. I succeeded to
I am facing a weird problem. You can see windows explorer have combo addressbar
I am facing a weird problem: I am encrypting the contents of a cookie.
I am facing a weird problem on BlackBerry JDE 4.2.0 and the 8100 simulator
I am facing a weird problem. While browsing the C code of a project,
I am facing a weird problem I have defined I a structure in a
I am facing a weird problem. I have got a file called in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.