8 Replies Latest reply on Sep 30, 2009 3:19 PM by frer

    Seam and JSF error message format

    rao

      Hi,


      I am evaluating seam for a new application.
      One of the things I came across is the error messages that are getting displayed on failing validations.


      If I have a required field (username) in a form, when value is not provided, it displays a message as follows:


      registerForm:usernameDecorate:username: Validation Error: Value is required.


      How do I change it do display only Value is required.


      I read some thing about message.properties. But, I didn't find  some thing specific to this.


      Thanks,
      Rao

        • 1. Re: Seam and JSF error message format
          msystems

          registerForm:usernameDecorate:username: Validation Error: Value is required.

          Is a standard JSF error message from Messages(_xx).properties:


          javax.faces.component.UIInput.REQUIRED\={0}: Validation Error: Value is required.



          where _xx is a language, e.g. _en for english and _da for danish etc.


          You can create you own Messages(_xx).properties and replace standard JSF messages (or other messages) with you own messages, e.g.:


          javax.faces.component.UIInput.REQUIRED\=Value is required.



          More info about JSF messages


          Or you can use Seam to load your custom messages - add the following lines to components.xml:


              <core:resource-loader>
                  <core:bundle-names>
                      <value>messages</value>
                  </core:bundle-names>
              </core:resource-loader>
          

           

          • 2. Re: Seam and JSF error message format
            msystems
            • 3. Re: Seam and JSF error message format
              rao

              Ken,


              Thanks for your help. Looks like I have some catching up to do on JSF.


              -Rao

              • 4. Re: Seam and JSF error message format
                rstevens

                Yes, but how do I get custom error messages to appear for NotNull values like, Credit card number is required?


                The booking example has this code in booking.java


                   @NotNull(message="Credit card number is required")
                   @Length(min=16, max=16, message="Credit card number must 16 digits long")
                   @Pattern(regex="^\\d*$", message="Credit card number must be numeric")
                   public String getCreditCard()
                   {
                      return creditCard;
                   }



                If I submit the form to book a hotel, it just shows the error message, value is required. How do I get the text Credit card number is required to display?


                And, how do I get that custom error to display on top of the form?





                • 5. Re: Seam and JSF error message format
                  oneworld95

                  I know this thread is from awhile back, but this can help for anyone who runs into this issue: Add a

                  converterMessage="Credit card number is required"

                  to your XHTML tag and the error will display. Not sure why this works, but it did on my project. I had the same issue, where the message attribute on the annotations didn't pass through; it would only display the default error message. Maybe someone can shed some light on this.

                  • 6. Re: Seam and JSF error message format
                    frer

                    How would it be possible to change the {0} value.  I don't want the full component id path but I'd like to have the attribute name so instead of having an error message like:





                    registerForm:usernameDecorate:username: Validation Error: Value is required.



                    I'd like to have





                    username: Validation Error: Value is required.



                    I know how to change the properties files...its really the value of the attribute that is problematic in my case.


                    Thank you,


                    Francois

                    • 7. Re: Seam and JSF error message format
                      qbit42

                      This is easy to accomplish. Just add label="username" to your inputText and the error message will use the label instead of the id.

                      • 8. Re: Seam and JSF error message format
                        frer

                        Thanks Matthias you are absolutely right.  That does do the trick!


                        I was looking too far :)