1 Reply Latest reply on Dec 30, 2008 4:58 PM by glwittel-proofpoint

    Link Title and Parameterized Resource Messages

    glwittel-proofpoint
      Hi,

      I'm trying to add a 'title' element to <s:link>, however the title text is parameterized text from a resource bundle.  Is there any way I can do this?

      e.g.

      msg=Hello {0}
      <s:link ... title="#{messages['msg']}">...</s:link>

      Would result in a title of "Hello {0}".  Basically I'd want to pass the message through h:outputFormat first so I get "Hello blah".  I can't cheat and do something like:  title="#{messages['msg']}#{blah}"  as the ordering would be different in some languages.

      Any suggestions?
      Thanks,
      -Greg
        • 1. Re: Link Title and Parameterized Resource Messages
          glwittel-proofpoint

          Awesome thanks!  I've documented what I did in case others are interested:


          Since we're using Facelets I used the following taglib function to call our formatter function:



          <function>
                <function-name>formatMessage</function-name
                <function-class>com.somecompany.util.JSFUtils</function-class>
                <!-- The actual signature is fn(String, Object...) but varargs ... is
                not supported correctly by the reflection functions in: 
                   com.sun.facelets.compiler.TagLibraryConfig.java: 
                   com.sun.facelets.util.ReflectionUtil.forName()
                -->
                <function-signature>java.lang.String getMessageFromFacesBundle(java.lang.String, java.lang.Object[])</function-signature>
           </function>




          In the library JSFUtils, the function pulls the ResourceBundle's message and runs MessageFormat as described:
            

          java.text.MessageFormat.format(msg, parameters);


          Where msg is a String containing the text retrieved from the bundle, and parameters is the Object... parameter


          After this its just a matter of using the taglib:


          ... title="#{myns:formatMessage('message.idstring', param1)}"



          -Greg