13 Replies Latest reply on Jan 23, 2008 5:52 PM by Gene Campbell

    Why control IDs in validation messages?

    Matthew Lieder Apprentice

      Why are my validation error messages showing up like "formId:panelId:controlId: Validation Error: Value is required" instead of "Validation Error: Value is required"? How can I fix that?

      Also, when I have a h:message attached to a specific control, can I make the message show just the "value is required" part?

        • 1. Re: Why control IDs in validation messages?
          Pete Muir Master

          Set the correct message in messages.properties

          javax.faces.component.UIInput.REQUIRED=value is required


          • 2. Re: Why control IDs in validation messages?
            Matthew Lieder Apprentice

            But if I do that, maybe changing it to "required value", wouldn't that just change the resulting error to "formId:panelId:controlId: Validation Error: required value"? That doesn't help at all :/

            • 3. Re: Why control IDs in validation messages?
              whafrog Newbie

              The default messages are parameterized, I think the form control is {2}. You can include these parameters or not when you override.

              • 4. Re: Why control IDs in validation messages?
                Gerardo Segura Newbie

                I experienced this too, I started from jpa example. At first the message displayed correct (with no Id).

                Although it doesn't seems related (and I didn't have time find out exactly the reason) I think it was about messing around with the default language and not including the proper messages_XX.properties in WEB-INF/classes.

                After correcting that error in my ant script I noticed the ids in the messages were gone, but again, didn't have a chance to confirm if that was in fact the reason. I suspected of that because other related things remained equal.

                • 5. Re: Why control IDs in validation messages?
                  Matthew Lieder Apprentice

                  Thanks for the help guys. Here are the different possible fixes I've found, for reference:

                  1. In WEB_INF/classes/messages_XX.properties, put:

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

                  The default value is "{0}: Validation Error: Value is required."

                  2. Use the "label" attribute on the input controls to replace"formId:containerId:controlId" with a friendly name.

                  3. Use the "requiredMessage" attribute on the input controls to completely override the REQUIRED message. This is what I ended up doing.

                  • 6. Re: Why control IDs in validation messages?
                    Cyrill Rüttimann Newbie

                    I am fighting with the same problem. I have the following setup:


                    <?xml version="1.0" encoding="UTF-8"?>
                    <faces-config version="1.2"
                     xmlns="http://java.sun.com/xml/ns/javaee"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
                    
                     <!-- Facelets Setup -->
                     <application>
                     <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
                     <locale-config>
                     <default-locale>en</default-locale>
                     <supported-locale>de</supported-locale>
                     <supported-locale>de_CH</supported-locale>
                     </locale-config>
                     </application>
                    </faces-config>
                    



                    <?xml version='1.0' encoding='UTF-8' ?>
                    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:h="http://java.sun.com/jsf/html">
                     <head>
                     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                     <title>Training Plattform Register Start</title>
                     <link href="css/screen.css" rel="stylesheet" type="text/css" />
                     </head>
                     <body>
                     <ui:composition template="template.xhtml">
                     <ui:define name="content">
                     <h:form id="register">
                     <s:validateAll>
                     <f:facet name="aroundInvalidField">
                     <s:span styleClass="errors"/>
                     </f:facet>
                     <f:facet name="afterInvalidField">
                     <s:div styleClass="errors">
                     <s:message />
                     </s:div>
                     </f:facet>
                     <div class="entry">
                     <div class="label">
                     <h:outputText value="#{messages.label_firstName}" />
                     </div>
                     <div class="input">
                     <s:decorate id="firstNameDecorate">
                     <h:inputText id="firstName" value="#{customer.firstName}" required="true" />
                     </s:decorate>
                     </div>
                     </div>
                     </div>
                     </s:validateAll>
                     <div class="entry errors">
                     <h:messages globalOnly="true"/>
                     </div>
                     <div class="input">
                     <h:commandButton id="register" value="#{messages.button_register}" action="#{customerRegistration.preRegisterCustomer}" />
                     </div>
                     </h:form>
                     </ui:define>
                     </ui:composition>
                     </body>
                    </html>
                    
                    



                     @NotNull
                     @Length(max = 50)
                     public String getFirstName() {
                     return mFirstName;
                     }
                    
                    


                    I do not see a problem here and no difference between the hotel booking example. But, In my case the formid,containerid and controlid are displayed before the validation message. I did not found a reasonable resolution to this problem. Anyone?

                    Regards,
                    Cyrill

                    • 7. Re: Why control IDs in validation messages?
                      Cyrill Rüttimann Newbie

                      The outcome for a german browser is:

                      Vorname:

                      register:firstNameDecorate:firstName: Validierungs-Fehler: Wert wird benötigt.


                      • 8. Re: Why control IDs in validation messages?
                        Matthew Lieder Apprentice

                        Did you see my previous post? There are (at least) three solutions available for that problem.

                        • 9. Re: Why control IDs in validation messages?
                          Cyrill Rüttimann Newbie

                          Please can you explain solution 2 & 3 a litte bit further? I do not know what you mean. The input component has no such attribute for instance.

                          Thank you very much!

                          • 10. Re: Why control IDs in validation messages?
                            Cyrill Rüttimann Newbie

                            My Facelets-Editor just did not showed me those two attributes - but they are listed in the JSF-Javadoc:
                            - label --> The error output is still very noise, but not so cryptical as before
                            - requiredMessage --> I do a lot of work (translations) I not want to do again

                            Maybe I should dive a bit into the code ...

                            • 11. Re: Why control IDs in validation messages?
                              Cyrill Rüttimann Newbie

                              I just discovered, that the validation messages from hibernate validator are displayed as in the hibernate validator message bundle except for instance the @NotNull - this is coming from the JSF framework because I have to switch on the attribute required="true". I have now modified


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


                              to have an uniform message for each input field. For me, this is the easiest way. For me, the validation thing it is still not transparent because some things come from the JSF Validation Framework and some pieces from hibernate validator framework. Why that is clear because of the way the frameworks are plugged in into seam and where the validation occures. Maybe there is a way to uniform this behaviour?

                              • 12. Re: Why control IDs in validation messages?
                                Pete Muir Master

                                required="true"/@NotNull is the only point at which you have to break DRY. This is currently unavoidable, sorry.

                                • 13. Re: Why control IDs in validation messages?
                                  Gene Campbell Newbie

                                  I want thank the posters of this thread so much for this topic. I am learning JSF, Seam and Facelets all at the same time. (I have been coding Java since version 1.0.2, but slipped a bit behind the curve as of late.) I didn't see the messages.properties connection in the Seam documentation I have, and I didn't make the connection on my own, so I was totally lost.

                                  I ended up with #3 for now.