5 Replies Latest reply on Dec 1, 2009 2:28 PM by mgvanbochove

    How to put a parameter into a localized string

      Hello!

      On my JSF page, i have a localized outputtext-element, for example:

      '''<h:outputText value="#{messages['myMessage]}" />'''

      In my messages-en.properties, i have something like this string:
      myMessage=Welcome to ''{0}''! Have fun!

      How can i pass a parameter to the messages-array, to fill the {0}-placeholder?

      Thanks in advance!
        • 1. Re: How to put a parameter into a localized string
          ztiringer

          @In
          private FacesMessages facesMessages;


          and then


          facesMessages.addFromResourceBundle( myMessage, param );

          • 2. Re: How to put a parameter into a localized string

            Thank you, Zoltan! But what i needed was a solution to use directly on a jsf page. I finally came up with this one, which works fine for me:


            <h:outputFormat value="#{messages['myParamMessage']}">
              <!-- put parameter into localized string -->
              <f:param value="#{param}"/>
            </h:outputFormat>



            • 3. Re: How to put a parameter into a localized string
              mgvanbochove
              Is it also possible to use this construction for a attribute of a tag. example:

              <rich:simpleTogglePanel switchType="ajax" label="message from messagebundle with paramters">
              ...
              </rich:simpleTogglePanel>


              I should want something like this, but unfortunately the value attribute of the attribute core tag (f:attribute) is required and can't use it's body:

                    <rich:simpleTogglePanel switchType="ajax">
                      <f:attribute name="label">
                          <!-- value attribute determined by result of outputFormat -->
                          <h:outputFormat value="#{messages['myParamMessage']}">
                            <!-- put parameter into localized string -->
                            <f:param value="#{param}"/>
                          </h:outputFormat>         
                      </f:attribute>
              ...
                    </rich:simpleTogglePanel>

              Is there a solution to this problem?
              • 4. Re: How to put a parameter into a localized string

                Ingo Fischer wrote on Nov 19, 2009 23:01:


                Thank you, Zoltan! But what i needed was a solution to use directly on a jsf page. I finally came up with this one, which works fine for me:


                You can use



                "#{interpolator.interpolate(messages['myMessage'], myParam1, myParam2)}"



                • 5. Re: How to put a parameter into a localized string
                  mgvanbochove

                  Thank you, it works!