Search code examples
springjsf-2bean-validationhibernate-validator

Hibernate Validation doesn't display custom error messages in JSF 2


i am using hibernate validation (4.2.0 Final) with JSF 2 and Spring and here's my configuration:

1- applicationContext:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
    <list>

    <value>classpath:messages/ValidationMessages</value>
    <value>classpath:messages/application</value>

    </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    </bean> 

2- faces-config.xml:

<resource-bundle>
           <base-name>messages.ValidationMessages</base-name>
        </resource-bundle>

when trying to use the following:

@NotBlank(message = "{name.required}")
private String name;

it doesn't work, it doesn't display the message from property file, it displays {name.required}

please advise why it's not working.


Solution

  • problem was that ValidationMessages.properties is not under the classpath directly, i was putting it inside a messages folder in the classpath, when i moved it to be under classpath directly it works fine now.