0

I try to override the default Hibernate Validator messages without success though. I am already using a resource bundle for several text which works pretty fine. The problem is with the messages of the Validator.

In detail:

I have created the following file: ValidationMessages_de.properties and placed it under \src\main\resources\translations\ValidationMessages_de.properties . The file has following resources: org.hibernate.validator.constraints.NotBlank.message=Value is required. org.hibernate.validator.constraints.NotEmpty.message=Value is required.

My faces-config.xml has following content:

<application>
    <locale-config>
        <default-locale>de</default-locale>
        <supported-locale>de</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>translations.messages</base-name>
        <var>msg</var>
    </resource-bundle>
    <resource-bundle>
        <base-name>translations.ValidationMessages</base-name>
        <var>validMsgs</var>
    </resource-bundle>
    <message-bundle>
    translations.ValidationMessages
    </message-bundle>
</application>

For validation I am using the following annotations: @NotEmpty @NotBlank

I tried also following:

  1. Move the ValidationMessages_de.properties to another directory
  2. Created a ValidationMessages.properties as also a ValidationMessages_de_DE.properties

None of the above solves the problem. When validating, Hibernate gives me the default message for the German locale : darf nicht leer sein

What am I missing ?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Stephan
  • 696
  • 15
  • 37
  • What that is described in http://stackoverflow.com/questions/7093468/how-to-add-custom-error-messages-in-hibernate-validator and http://stackoverflow.com/questions/21630589/overwriting-default-hibernate-validator-messages is different from your case? – Kukeltje Apr 11 '17 at 13:01
  • Is it in your deployed application – Kukeltje Apr 12 '17 at 06:46
  • Yes. Primefaces client side validation is reading already text from this message bundle without any problems. Hibernate validator seems to have a problem reading. – Stephan Apr 12 '17 at 06:52

1 Answers1

0

Although i had configured my faces-config.xml to look in the translations for some reasons it was unable to read from the the resources.

Once i moved the files under src\main\resources\ everything started to work.

Stephan
  • 696
  • 15
  • 37
  • You configured faces-config, so you told JSF about it. Hibernate still has no idea. AFAIK, there is no way to configure this path for Hibernate. – Vsevolod Golovanov May 02 '17 at 12:45