Results 1 to 3 of 3

Thread: Problem with typeMismatch error

  1. #1
    Join Date
    Sep 2004
    Location
    Peterborough, UK
    Posts
    2

    Default Problem with typeMismatch error

    I have a SimpleFormController which has an initBinder method for dates

    Code:
        	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        	df.setLenient(false);
        	binder.registerCustomEditor(Date.class, null, new CustomDateEditor(df, true));
    I have added a message for typeMismatch.java.util.Date in my messages.properties.

    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. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    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. #3
    Join Date
    Sep 2004
    Location
    Peterborough, UK
    Posts
    2

    Default 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

    Code:
    <spring&#58;bind path="printSearch.*">
        <c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
             <c&#58;out value="$&#123;error&#125;"/><br>
        </c&#58;forEach>
    </spring&#58;bind>
    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

    Code:
    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;;
        &#125;
        public void validate&#40;Object obj, Errors errors&#41; &#123;
            TicketPrintSearch p = &#40;TicketPrintSearch&#41; obj;
        &#125;
    &#125;
    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.

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 4
    Last Post: Nov 5th, 2004, 03:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •