It was not good, smrutimo. Property editors definitely do not seem fit for this, and implementing a custom tag is not a nice idea for me, as my Spring knowledge is entry level, I'm still understanding many of its details and mechanics.
But finally, I found a solution. It feels like I'm doing it the 'rough' way, but works and is very simple.
For anyone with a similar problem, here is the code (inside the controller):
Code:
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
super.initBinder(request, binder);
binder.setBindingErrorProcessor(new BindingErrorProcessorImpl(binder.getBindingErrorProcessor()));
}
public class BindingErrorProcessorImpl implements BindingErrorProcessor {
private BindingErrorProcessor defaultBindingErrorProcessor;
public BindingErrorProcessorImpl(BindingErrorProcessor defaultBindingErrorProcessor) {
defaultBindingErrorProcessor = this.defaultBindingErrorProcessor;
}
@Override
public void processMissingFieldError(String missingField, BindingResult bindingResult) {
defaultBindingErrorProcessor.processMissingFieldError(missingField, bindingResult);
}
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
if(ex.getPropertyChangeEvent().getPropertyName().equals("myPropertyName")) {
bindingResult.rejectValue("myPropertyName", "validation.invalid_field");
} else {
defaultBindingErrorProcessor.processPropertyAccessException(ex, bindingResult);
}
}
}
For discussions about the code, here is the source:
http://stackoverflow.com/questions/6...-error-message
Bye!