JSR-303 Add Default Confirmation Message

I am using the Apache Bean JSR-303 Validation Implementation, and I was curious if there is a way to add a message to the default message that is defined in the ValidationMessages.propeties file.

those. @NotNull(message="Object objectField name {message}")

Conclusion: the object of the object. The field name cannot be null.

If the message simply adds a 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}") 

It just seems very verbose.

+4
source share
1 answer

No. There is no way to do this.

See section 4.3.1.1 of the JSR-303 for more information.

You can do it:

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 (according to JSR) must be recursively enabled. I donโ€™t know how compatible Apache Validator is at this time, but I can say that the Hibernate Validator (100% TCK-compatible) will do this.

+2
source

All Articles