8 Replies Latest reply on Nov 6, 2009 12:30 PM by Walter White

    Resolving Messages

    Walter White Novice

      Hi all,


      I have been having issues resolving messages for quite some time now.  In my faces-context.xml, I declared en-US as my default and only supported locale and whenever I attempt to use messages throughout the site, they seem to work sporadically.  What else am I missing?


      1. set locales in faces-config.xml
      2. add messages to /WEB-INF/messagesenUS.properties
      3. use in xhtml pages or actions or in JSF components



      Walter

        • 1. Re: Resolving Messages
          Leo van den berg Master

          Hi,


          messages should be accesible on the classpath and I usually place them in the class-dir under WEBINF. Further more the application should recognize that the browser only talks enUS.


          Leo

          • 2. Re: Resolving Messages
            Walter White Novice

            Thanks Leo, I figured it was something simple like that.  I'm just testing that now, I'll post the results in a bit.

            • 3. Re: Resolving Messages
              Walter White Novice

              Awesome - that was it.  It works great now.



              Walter

              • 4. Re: Resolving Messages
                Walter White Novice

                Leo, I should have posted back sooner.  Actually, it works well, but for validation, it does not work.  Instead of getting:


                Email Address is not a valid email address


                I get:


                value is not a valid email address



                What else do I need to change to make those work again?




                Walter

                • 5. Re: Resolving Messages
                  Leo van den berg Master

                  Hi Walter,


                  I've you have defined for instance the following in your message file:




                  validator.email={0} must be a well-formed email address
                  person_email = eMail




                  And let's assume you are using the following standard Seam-way for input and validation:




                   <s:decorate id="emailField" template="../layout/edit.xhtml">
                       <ui:define name="label">#{messages['person_email']}</ui:define>
                            <h:inputText value="#{yourBean.email}" label="#{messages['person_email']}">
                                  <a4j:support event="onblur" reRender="emailField" 
                                             ajaxSingle="true" bypassUpdates="true" eventsQueue="inputQueue" />
                            </h:inputText>
                  </s:decorate>



                  After validation (and it's not ok) the message is displayed and the label works as value for the {0} placeholder.
                  Because this is also coming from the message bundle the label-value gets replaced with a localized string.


                  Leo




                  • 6. Re: Resolving Messages
                    Walter White Novice

                    Leo,


                    This may be a dumb question, but you have to define your own edit layout right like this:


                    (this is my edit.xhtml)




                    |<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                                        xmlns:ui="http://java.sun.com/jsf/facelets"
                                        xmlns:h="http://java.sun.com/jsf/html"
                                        xmlns:f="http://java.sun.com/jsf/core"
                                        xmlns:s="http://jboss.com/products/seam/taglib">
                         <div class="field">
                              <s:label styleClass="label #{invalid?'errors':''}">
                                   <ui:insert name="label"/>
                                   <s:span styleClass="required" rendered="#{required}">*</s:span>
                              </s:label>
                              <span class="input #{invalid?'errors':''}">
                                   <s:validateAll>
                                        <ui:insert/>
                                   </s:validateAll>
                              </span>
                              <s:message styleClass="error errors"/>
                         </div>
                    </ui:composition>|







                    <s:decorate id="firstNameDecorate" template="${decorator.editLayout}">
                                                  <ui:define name="label">#{messages['user.firstName']}</ui:define>
                                                  <h:inputText id="firstName" required="true" value="#{contactBean.firstName}" label="#{messages['user.firstName']}">
                                                       <a:support event="onblur" reRender="firstNameDecorate"/>
                                                  </h:inputText>
                                             </s:decorate>




                    I have user.firstName in my messages.properties.  The ${decorator.editLayout} is a property that gets replaced when I run maven.



                    The labels worked before I must have a wrong property specified somewhere as it was being picked up.



                    Walter

                    • 7. Re: Resolving Messages
                      Leo van den berg Master

                      Hi,


                      If it works with a literal string, it has to do with Facelets, if its still in the code when you render, it will get confused because the ${} is the old JSF EL way


                      Leo

                      • 8. Re: Resolving Messages
                        Walter White Novice

                        No, it gets pulled out as soon as the resources are processed, so jetty/facelets would never see that.



                        Walter