
Originally Posted by
Marten Deinum
It works in EXACTLY the same way as all the other validation messages. Check the
DefaultMessageCodeResolver for the list of registered error codes.
Excuse my ignorance but I don't understand then how the PortletDataRequestBinder associates the error from the CustomDateEditor to the "errorCode" intercepted by the DefaultMessageCodesResolver?
eg in initBinder;
Code:
protected void initBinder(PortletRequest request, PortletRequestDataBinder binder)
throws Exception {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
super.initBinder(request, binder);
}
As opposed to in the Validator implementation where I control what the error code is at the time of the population of the Error object;
Code:
public void validate(Object target, Errors errors) {
ValidationUtils.rejectIfEmpty(errors, "userName", "userName.empty");
// ...
}
All of which appears to end up (eventually) in AbstractBindingResult.resolveMessageCodes :
Code:
public String[] resolveMessageCodes(String errorCode, String field) {
String fixedField = fixedField(field);
Class fieldType = getFieldType(fixedField);
return getMessageCodesResolver().resolveMessageCodes(errorCode, getObjectName(), fixedField, fieldType);
}
At which point the DefaultMessageCodeResolver is allowed to do its thing.
It's what is in-between the initBind() - which doesn't have the errorCode specified (by me at least) and the DefaultMessageCodeResolver being the part I don't fully understand how I control that, or what its default value might be.
(I'm unable to find out at run time what the default value is as I cannot hook a debugger up to the Oracle Portal server - a very nasty set of firewall rules stops me, and my rather incomplete knowledge of this).
Amit: I can bind the error to the *field* on the JSP just great (i.e. show the message text next to the field that's wrong), what is eluding me is control of the errorCode from the CustomDateEditor - I'm just getting its exception message.