5 Replies Latest reply on May 17, 2011 10:39 AM by dandii

    default message of <rich:message> for validation errors

    dandii

      Hi community,

       

      I would like to change the default message for the rcih validator.

      My example:

       

      • I have the following been (Hibernate):

       

      @Entity
      @Table(name = "example")
      public class Example ... {    @Min(value=0, message="My Message")
          private Double d;
          ...
          ...
      }
      

       

      • My xhtml page looks like:

       

      ...        
        <h:inputText id="example" value="#{example.d}">
          <rich:validator event="keyup"/>
        </h:inputText>
      ...
      

       

      The validation works very fine and if I enter the number "-2" I get my configured message. The validation also checks if I enter some characters like "asdf" where I'm getting "value must be a number between 4.9E-324 and 1.7976931348623157E308".

       

      My question is where can I change this text?

       

      Regards,

      Andi

        • 1. default message of <rich:message> for validation errors
          mp911de

          Hi Andi,

          take a look at org.richfaces.application.FacesMessages. You'll find there a bunch of Message-Ids. Just include the Id with your translation in your messagebundle.

           

          Best regards,

          Mark

          1 of 1 people found this helpful
          • 2. default message of <rich:message> for validation errors
            ilya_shaikovsky

            Also various localization available at JSF and hibernate and JSF levels. just check the docs for them

            • 3. default message of <rich:message> for validation errors
              dandii

              Hi again,

               

              thanks for your reply, my Problem is not to change the localization. The message "value must be a number between 4.9E-324 and 1.7976931348623157E308" is to long for my purpose, I would like to display a shorter message.

               

              Regards,

              Andi

              • 4. default message of <rich:message> for validation errors
                ssamayoagt

                As other fellows said you must check documentation of JSF and Bean Validation API.

                 

                @Min is Bean Validation annotation.

                 

                This is part of the Hibernate Validator (JSR-303 refence implementation):

                 

                2.2.4. Message interpolation

                As we will see in Chapter 3, Creating custom constraints each constraint definition must

                define a default message descriptor. This message can be overridden at declaration time

                using the message attribute of the constraint. You can see this in Example 2.13, “Driver”. This

                message descriptors get interpolated when a constraint validation fails using the configured

                MessageInterpolator. The interpolator will try to resolve any message parameters, meaning

                string literals enclosed in braces. In order to resolve these parameters Hibernate Validator's default

                MessageInterpolator first recursively resolves parameters against a custom ResourceBundle

                called ValidationMessages.properties at the root of the classpath (It is up to you to

                create this file). If no further replacements are possible against the custom bundle the default 

                ResourceBundle under /org/hibernate/validator/ValidationMessages.properties gets

                evaluated. If a replacement occurs against the default bundle the algorithm looks again at the

                custom bundle (and so on). Once no further replacements against these two resource bundles

                are possible remaining parameters are getting resolved against the attributes of the constraint to

                be validated.

                 

                Is up to you to look for the documentation and do further reading.

                 

                Regards.

                • 5. Re: default message of <rich:message> for validation errors
                  dandii

                  Hi,

                   

                  thanks, now I understand your responses....

                  Here ist the link to the documentation of the hibernate validator....

                   

                  http://docs.jboss.org/hibernate/validator/4.1/reference/en-US/html/validator-usingvalidator.html#section-message-interpolation

                   

                  Andi