Announcement Announcement Module
No announcement yet.
Problem with typeMismatch error Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with typeMismatch error

    I have a SimpleFormController which has an initBinder method for dates

        	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        	binder.registerCustomEditor(Date.class, null, new CustomDateEditor(df, true));
    I have added a message for in my

    When I enter a deliberately incorrect date (eg 2004/09/33) I see my message displayed briefly, and then replaced with the "Failed to convert ..." message. If I use the browser's back button I get back to the page with my message displayed.

    Why is this occurring and how can I avoid that second message?

  • #2
    This should work OK.

    It sounds like your page is doing something on the onLoad event or similar. Can you post the relevant form and form handler?


    • #3
      Problem with typeMismatch error

      Nope - this page does have anything attached to an onLoad event (or similar). I do have a bit of javascript (to handle date validation / and pop up calendar) which I have disabled to try this.

      The form is too big to post but in the form I display errors

      <spring&#58;bind path="printSearch.*">
          <c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
               <c&#58;out value="$&#123;error&#125;"/><br>
      As for the form handler (again I am excerpting)

      initBinder(HttpServletRequest req, ServletRequestDataBinder binder) is the code already posted.

      formBackingObject() just creates a new Object()
      referenceData() puts a few values in the model (for drop downs)
      onSubmit() can be ignored as I have stubbed it out and just returned a new ModelAndView to a fixed page and errors.getModel().

      I have similarly reduced the validator for this form to

      public class TicketPrintSearchValidator implements Validator &#123;
          private static final Logger logger = Logger.getLogger&#40;TicketPrintSearchValidator.class&#41;;
          public boolean supports&#40;Class clazz&#41; &#123;
              return clazz.equals&#40;TicketPrintSearch.class&#41;;
          public void validate&#40;Object obj, Errors errors&#41; &#123;
              TicketPrintSearch p = &#40;TicketPrintSearch&#41; obj;
      As you say it looks like it should work. I am still using version 1.0 of Spring, it is a currently live system, but I can update Spring if it will do any good.