PDA

View Full Version : Problem with typeMismatch error


andyl
Sep 27th, 2004, 01:00 PM
I have a SimpleFormController which has an initBinder method for dates


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?

katentim
Sep 28th, 2004, 06:47 AM
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?

andyl
Sep 28th, 2004, 07:49 AM
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:bind path="printSearch.*">
<c:forEach items="${status.errorMessages}" var="error">
<c:out value="${error}"/><br>
</c:forEach>
</spring: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


public class TicketPrintSearchValidator implements Validator {
private static final Logger logger = Logger.getLogger(TicketPrintSearchValidator.class) ;

public boolean supports(Class clazz) {
return clazz.equals(TicketPrintSearch.class);
}
public void validate(Object obj, Errors errors) {
TicketPrintSearch p = (TicketPrintSearch) 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.