Hibernate Custom Validator Messages Spring MVC











up vote
0
down vote

favorite












I am trying to customize messages for Hibernate validation annotations (NOTNULL , NOTEMPTY ,...) so that the application is able to read them from .proparties file.



I tried the solutions from the answer here: use custom validation in hibernate
hibernate validator



but nothing works for me i still get the deafult messages (may not be null , may not be empty , ....).



Code sample :



application context.xml :



<bean name="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource">
<ref bean="resourceBundleLocator" />
</property>
</bean>

<bean name="resourceBundleLocator"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>


user.java :



@NotNull
private String name;


messages.proparties :



user.name.notNull = incorrect name









share|improve this question


























    up vote
    0
    down vote

    favorite












    I am trying to customize messages for Hibernate validation annotations (NOTNULL , NOTEMPTY ,...) so that the application is able to read them from .proparties file.



    I tried the solutions from the answer here: use custom validation in hibernate
    hibernate validator



    but nothing works for me i still get the deafult messages (may not be null , may not be empty , ....).



    Code sample :



    application context.xml :



    <bean name="validator"
    class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="validationMessageSource">
    <ref bean="resourceBundleLocator" />
    </property>
    </bean>

    <bean name="resourceBundleLocator"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
    <list>
    <value>messages</value>
    </list>
    </property>
    </bean>


    user.java :



    @NotNull
    private String name;


    messages.proparties :



    user.name.notNull = incorrect name









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to customize messages for Hibernate validation annotations (NOTNULL , NOTEMPTY ,...) so that the application is able to read them from .proparties file.



      I tried the solutions from the answer here: use custom validation in hibernate
      hibernate validator



      but nothing works for me i still get the deafult messages (may not be null , may not be empty , ....).



      Code sample :



      application context.xml :



      <bean name="validator"
      class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
      <property name="validationMessageSource">
      <ref bean="resourceBundleLocator" />
      </property>
      </bean>

      <bean name="resourceBundleLocator"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
      <property name="basenames">
      <list>
      <value>messages</value>
      </list>
      </property>
      </bean>


      user.java :



      @NotNull
      private String name;


      messages.proparties :



      user.name.notNull = incorrect name









      share|improve this question













      I am trying to customize messages for Hibernate validation annotations (NOTNULL , NOTEMPTY ,...) so that the application is able to read them from .proparties file.



      I tried the solutions from the answer here: use custom validation in hibernate
      hibernate validator



      but nothing works for me i still get the deafult messages (may not be null , may not be empty , ....).



      Code sample :



      application context.xml :



      <bean name="validator"
      class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
      <property name="validationMessageSource">
      <ref bean="resourceBundleLocator" />
      </property>
      </bean>

      <bean name="resourceBundleLocator"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
      <property name="basenames">
      <list>
      <value>messages</value>
      </list>
      </property>
      </bean>


      user.java :



      @NotNull
      private String name;


      messages.proparties :



      user.name.notNull = incorrect name






      java spring hibernate






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 23 hours ago









      Mahmood Mousa

      53




      53
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You need to mention the key name on your @NotNull annotation.



          @NotNull(meassage="{user.name.notNull}")
          private String name;


          You can learn more from the link
          https://teamtreehouse.com/library/displaying-validation-messages






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372170%2fhibernate-custom-validator-messages-spring-mvc%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            You need to mention the key name on your @NotNull annotation.



            @NotNull(meassage="{user.name.notNull}")
            private String name;


            You can learn more from the link
            https://teamtreehouse.com/library/displaying-validation-messages






            share|improve this answer

























              up vote
              1
              down vote













              You need to mention the key name on your @NotNull annotation.



              @NotNull(meassage="{user.name.notNull}")
              private String name;


              You can learn more from the link
              https://teamtreehouse.com/library/displaying-validation-messages






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                You need to mention the key name on your @NotNull annotation.



                @NotNull(meassage="{user.name.notNull}")
                private String name;


                You can learn more from the link
                https://teamtreehouse.com/library/displaying-validation-messages






                share|improve this answer












                You need to mention the key name on your @NotNull annotation.



                @NotNull(meassage="{user.name.notNull}")
                private String name;


                You can learn more from the link
                https://teamtreehouse.com/library/displaying-validation-messages







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 23 hours ago









                Pooja Aggarwal

                6757




                6757






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372170%2fhibernate-custom-validator-messages-spring-mvc%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    SQL update select statement

                    'app-layout' is not a known element: how to share Component with different Modules