9 Replies Latest reply on Nov 26, 2006 4:35 PM by rlhr

    i18n validation message during test

    atao

      Hello,

      I'm trying to add i18n messages to booking example, something like:

      @NotNull(message="#{messages['booking.credit.card.not.null']}")
      @Length(min=16, max=16, message="#{messages['booking.credit.card.number.wrong.length']}")
      @Pattern(regex="^\\d*$", message="#{messages['booking.credit.card.number.invalid']}")
      public String getCreditCard()
      {
      return creditCard;
      }

      It's work fine when I work with a navigator. But during the test, BookingTest.renderResponse fails. The string returned by
      ( (FacesMessage) messages.next() ).getSummary()
      is
      #{messages['booking.credit.card.not.null']}
      and not the pattern associated with the key "booking.credit.card.not.null".

      Is it the expected behavior?

        • 1. Re: i18n validation message during test
          gavin.king

          Yes, Hibernate Validator wants you to use:

          @NotNull(message="{booking.credit.card.not.null}")


          However, Emmanuel and I are currently working on some integration b/w Seam and Hibernate Validator so that you can use #{messages['...']} for consistency.

          • 2. Re: i18n validation message during test
            atao

            ATM, in a deploiement under jBoss server,

            @NotNull(message="#{messages['booking.credit.card.not.null']}")

            works with messages_loc.properties under {booking_home}/resources/WEB-INF/classes

            and

            @NotNull(message="{booking.credit.card.not.null}")

            doesn't work even with ValidatorMessages_loc.properties under {booking_home}/resources/WEB-INF/classes.

            I don't see what is wrong!

            Pierre

            • 3. Re: i18n validation message during test
              gavin.king

              Oh, I'm wrong, #{messages['booking.credit.card.not.null']} does work after all.

              • 4. Re: i18n validation message during test
                atao

                Ok

                So I come back to my first question: I get the literal string

                #{message['any.key']}

                and not the associated pattern when I test BookingTest.renderResponse

                is it the expected behavior?

                • 5. Re: i18n validation message during test
                  gavin.king

                  message!=messages

                  • 6. Re: i18n validation message during test
                    atao

                    Oups! Sorry, the mistake is only here. The code is really like:

                    @Length(min=16, max=16, message="#{messages['booking.credit.card.number.wrong.length']}")

                    and during test, ( (FacesMessage) messages.next() ).getSummary() returns

                    #{messages['booking.credit.card.number.wrong.length']}

                    • 7. Re: i18n validation message during test

                      Hello,

                      I tried to setup custom messages for the hibernate validation annotation but without success yet.

                      I have a ValidatorMessages.properties (defining all the default message for hibernate validators) file in my ear file so that I don't get an exception at server startup.
                      All my properties file are under WEB-INF/classes in the war file.
                      In compoments.xml, I define all these files and everything works fine except validations still return the default "Validation Error" message.

                      I also tried to define the following in the faces-config.xml:

                      <message-bundle>ValidatorMessages</message-bundle>
                      
                       <locale-config>
                       <default-locale>en</default-locale>
                       <supported-locale>en</supported-locale>
                       <supported-locale>fr</supported-locale>
                       </locale-config>
                      

                      But it didn't change anything...

                      I tried to use both syntax:

                      @NotNull(message="{validator.my.message}")
                       and
                      @NotNull(message="#{messages['validator.my.message']}")
                      


                      Without much success.

                      Does anyone know how to set this up? I'm sure I must have missed something somewhere, but I can't see what.

                      Thanks,

                      Richard

                      • 8. Re: i18n validation message during test
                        atao

                        Richard

                        read the thread

                        http://www.jboss.com/index.html?module=bb&op=viewtopic&t=93507

                        to get some more explanations about NotNull annotation and validation tag.

                        Pierre

                        • 9. Re: i18n validation message during test

                          Hi Pierre,

                          Thanks for the link, I'm going to take a look at it.

                          Richard