By default, ValidationMessages.properties can be located in root of my classpath. Can I change the location of this file like com.myapp.Anything.properties?
Java Bean validation specifications require that each constraint annotation must include a 'message' element definition. The message element value represents validation error message. This element usage is optional on client side. If not specified a default message resource key is resolved and displayed.
This is the default behavior which can be modified by implementing javax.validation.MessageInterpolator Java Bean Validation specification supports Unified Expression Language (JSR 341) for evaluating dynamic expression in the validation messages that's the reason we have to include 'javax.el' dependency in our projects.
In such a case, you may want to use the validateProperty () method, which is called with a constrained object and the name of the bean property to be validated: Here, a constraint violation will be raised because an empty string has been passed as a value for the name field.
Java Bean Validation specification supports Unified Expression Language (JSR 341) for evaluating dynamic expression in the validation messages that's the reason we have to include 'javax.el' dependency in our projects. Within the messages, constraint annotation element values can be referenced as ' {theElementName}'.
From the JSR-303 specification:
4.3.1.1. Default message interpolation algorithm The default message interpolator uses the following steps:
- Message parameters are extracted from the message string and used as keys to search the ResourceBundle named ValidationMessages (often materialized as the property file /ValidationMessages.properties and its locale variations) using the defined locale (see below). If a property is found, the message parameter is re- placed with the property value in the message string. Step 1 is applied recursively until no replacement is per- formed (i.e. a message parameter value can itself contain a message parameter).
It seems that this is the default and the suggestion. To back this up the JSR-303 TCK uses TestNG to move them to the "WEB-INF/classes/" directory which is the same as "./" on the resources classpath.
(You can experiment with it but that's about all I can figure out.)
Sorry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With