Announcement Announcement Module
No announcement yet.
Converter Trouble with JodaTime - Please Help Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converter Trouble with JodaTime - Please Help

    I am a bit confused about Conversion. I have read the documentation and unfortunately am either not getting it or not understanding the process the application goes through on submit.

    The goal is that the DateTime objects in my Domain model will get passed from a webpage via a format, converted, and then added to the domain model to be persisted elsewhere. From the blog I read on it appears that using the @DateTimeFormat(format="blah") should allow for conversion. However, I have all the parts correctly setup but yet I receive the following on POST:
    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.persistence.Column 
        @org.springframework.format.annotation.DateTimeFormat org.joda.time.DateTime for 
        value 12/31/2011 18:14 ; nested exception is java.lang.IllegalArgumentException: 
            Invalid format: "12/31/2011 18:14 " is malformed at " "
    Eventually I have to convert an "Integer" to another object (Webform passes it back as String from a Select List). I am NOT using Webflow. Any help would be appreciated. Below is all I think you might need to help me resolve this.

    Thanks in advance.

    I have a Domain Model of
    @Table(name = "RESERVATION")
    public class Reservation {
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "id")
        private int id;
        @ManyToOne(targetEntity = Account.class, fetch = FetchType.EAGER)
        @JoinColumn(name = "account_id")
        private Account owner;
        @Column(nullable = false)
        private String purpose;
        @Column(nullable = false)
        @DateTimeFormat(pattern="MM/dd/yyyy HH:mm")
        private DateTime startDate;
    My context.xml has the following:
    	<bean id="conversionService" class=""/>
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="webBindingInitializer">
    			<bean class="">
    				<property name="conversionService" ref="conversionService" />
    My Controller for Posts has:
       @RequestMapping(value = "add", method = RequestMethod.POST)
        public String addReservation(@ModelAttribute("reservation") Reservation reservation, BindingResult result,
    	    SessionStatus status) {
    	log.debug("RESERVATION: {}",reservation);
    	reservationValidator.validate(reservation, result);
    	log.debug("RESERVATION AFTER VALIDATION: {}",reservation);
    	if (result.hasErrors()) {
    	    return "addReservation";
    	try {"Creating Reservation {}",reservation);
    	} catch (Exception e) {
    	return "redirect:reservation";
    The JSP has the following:
    <form:form method="POST" modelAttribute="reservation">
    	<form:label path="purpose" cssClass="label">Reservation Purpose</form:label>
    	<form:input path="purpose" />
    	<form:errors path="purpose" cssClass="error" />
    	<form:label path="" cssClass="label">Select Frame:</form:label>
           <form:select path="">
    		<form:option value="0" label="Select" />
    		<form:options items="${frames}" itemValue="id" itemLabel="label" />
    	<form:errors path="" cssClass="error" />
    	<spring:bind path="reservation.startDate">
    	<form:label path="startDate">Start Date/Time</form:label>
    	<form:input path="startDate" cssClass="startDate" />
    	<form:errors path="startDate" />
    	<spring:bind path="reservation.stopDate">
    	<form:label path="stopDate">Start Date/Time</form:label>
    	<form:input path="stopDate" cssClass="stopDate" />
    	<form:errors path="stopDate" />
    	<input type="submit" value="Add" />