JSR-303 Append Default Validation Message
I am using the Apache Bean Validation implementation of JSR-303 and was curious if there is a way to append a message to the default message that is defined in the ValidationMessages.propeties
file.
I.E. @NotNull(message="Object objectField name {message}")
Output : Object objectField name may not be null
Where mess开发者_Python百科age would simply append the default message
Is this possible using the Apache Bean Validation 0.3 or Hibernate Validation 4.1.0-Final APIs???
Or am I forced to do something like this:
ValidationMessage.properites
javax.validation.constraints.NotNull.message=may not be null
Code :
@NotNull(message="Object objectField name {javax.validation.constraints.NotNull.message}")
Which just seems very verbose.
No. There's no way to do that.
See the JSR-303, section 4.3.1.1 for more information.
You could do this:
ValidationMessage.properties
custom.message=Object objectField name {javax.validation.constraints.NotNull.message}
Code
@NotNull(message="{custom.message}")
And get what you want. Custom message properties are (according to the JSR) supposed to be recursively resolved. I do not know how compatible the Apache Validator is at this time but I can tell you that the Hibernate Validator (being 100% TCK compliant) will do that.
精彩评论