kumar
kumar

Reputation: 595

Include field value inside error message using Hibernate Validator

I want to include the field value that is passed in the request, to be inlcuded in the validation message. but the entire string is displayed as it is, without substituting the field value. Am i missing anything here??

I am using following versions: javax.validation - 1.1.0.Final hibernate-validator - 5.0.1.Final

http://beanvalidation.org/1.1/spec/#message-expressions

My Bean Class:

@NotNull(message = "custom message for not null")
@Range(message="param1 ${validatedValue} must be within {min} and {max}.", min=0, max=90)
protected Double param1;

Actual error message displayed after range violation:

 param1 ${validatedValue} must be within 0 and 90.

my pom file for BV:

   <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.0.1.Final</version>
        <scope>provided</scope>
    </dependency>

Upvotes: 1

Views: 1359

Answers (2)

kumar
kumar

Reputation: 595

@Gunnar was correct. To avoid jboss loading default bean validation api's, I created the following xml file under web-inf directory and problem solved.

jboss-deployment-structure.xml:

 <jboss-deployment-structure>
   <deployment>
   <exclusions>
      <module name="javax.validation.api"/>
      <module name="org.hibernate.validator"/>
    </exclusions>
   </deployment>
 </jboss-deployment-structure>

Upvotes: 0

Gunnar
Gunnar

Reputation: 19020

EAP 6 comes with Bean Validation 1.0/Hibernate Validator 4.2 and these libraries take precedence. You may try to exclude these container modules (refer to e.g. this post for an explanation of how to do this) and package your own dependencies. But be aware that other modules might require the container-provided versions.

Upvotes: 1

Related Questions