I was able to get this to work with your code.
First I tried it exactly and it worked.
Then i copied and pasted my logic into these classes and it still worked.
I then renamed it and used it and my unit tests passed.
So the only difference I could see was that I had my implementation in a different file.
I have a follow up question now.
In the example below the error code defined in the @DecimalMin annotation is resolved in my spring controller as seen in the output. Yet it is not available in the jsp. The jsp uses the first code in the codes list.
Is there a way to pass the error code to the list of codes?
grossPay.custom.message=Dont do that
@DecimalMin(value="0.00",message="{grossPay.custom.message}")
public String postResult(@Valid @ModelAttribute("myModel") CustomModel model, BindingResult result) {
for (FieldError error : result.getFieldErrors()) {
System.out.println("Field Error in field: " + error.getField() + " with default message: "+ error.getDefaultMessage());
System.out.println("codes: ");
for (String s : error.getCodes()) {
System.out.println(s);
}
}
Field Error in field: grossPay with default message: Dont do that
codes:
DecimalMin.customModel.grossPay
DecimalMin.grossPay
DecimalMin.java.math.BigDecimal
DecimalMin
|