Hi I have some Ajax Forms
, where I use an Async POST
to send data to server...
If BindingResult
has an error I want show a message in view, after the input field, to explain the error, so this is my method in my controller:
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Map<String, String> create(@Valid MyClass myClass, BindingResult bindingResult, Model uiModel,
HttpServletRequest httpServletRequest, HttpServletResponse response, Locale locale) {
if (bindingResult.hasErrors()) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
Map<String, String> errorFields = new HashMap<String, String>();
for(FieldError fieldError : bindingResult.getFieldErrors()){
errorFields.put(fieldError.getField(), fieldError.getDefaultMessage());
}
return errorFields;
}
uiModel.asMap().clear();
myService.create(personale);
return null;
}
And it works, but fieldError.getDefaultMessage()
return an English message, but I want return a Localized message..
I know that I can do in this way:
@NotNull(message="{myMessage}")
private Field field;
But I wouldn't specify the localized message to each field, maybe can I use message.properties
file??
Is it possible??
Thank you!
EDIT
I readed this: another question about my problem, but I can't get from messagges...