Vote count:
0
I'm trying to resolve a default Spring message in an Ajax Controller to a more friendly message.
In the validations.properties file I put this entry:
typeMismatch.productImage.orderIndex=Sequence cannot be converted to a number.
If I debug the code block below, a call to fieldError.getCodes() returns amongst other things typeMismatch.productImage.orderIndex as one of the codes in the array.
My question is, how do I get the messageSource to resolve the hierarchical version of the message code? At the moment, it's not resolving and just using the default message, "typeMismatch", i.e the first code in the list of message codes for that field.
I'm guessing it's something wrong with the way I'm using getMessage...
if (ex.getResult().hasFieldErrors())
{
Map<String,String> fieldErrors = response.getFieldErrors();
for(FieldError fieldError: ex.getResult().getFieldErrors()) {
String field = fieldError.getField();
String message = messageSource.getMessage(fieldError.getCode(), fieldError.getArguments(), fieldError.getCode(), null);
fieldErrors.put(field, message);
}
}
asked 30 secs ago
Resolving message in BindingResult fieldError codes
Aucun commentaire:
Enregistrer un commentaire