2

I'm currently using the resourceBundle variable to get text values in my JSF code e.g. like this:

<h:outputText value="#{resourceBundle.welcomeMessage}" />

Is there any way, to put the message key in a variable, and give it as a dynamic parameter to the resource bundle? I was hoping to be able to do something like this:

<c:set var="name" value="#{'welcomeMessage'}" />
<h:outputText value="#{resourceBundle.get(name)}" />
Rune Aamodt
  • 2,551
  • 2
  • 23
  • 27

3 Answers3

1

Just create a dedicated ManagedBean with a method resolveKey(String key) from which call resourceBundle lookup and on view and use that bean.

jmj
  • 237,923
  • 42
  • 401
  • 438
1

Use h:outputFormat, see example: http://www.javabeat.net/tips/47-how-to-use-resource-bundle-in-jsf.html

Adam
  • 5,045
  • 1
  • 25
  • 31
1

The resource bundle takes dynamic parameter. Here is snippet from my project:

    <f:loadBundle basename="#{siteName}" var="bundle"/>
        ....
               <h:dataTable value="#{summary.restrictionList}" var="restrictionList" cellspacing="0" cellpadding="0"> 
               ....

                            <h:outputFormat value="#{bundle['summary.label.blockcodemsg']}">
                                <f:param value="#{restrictionList['lastFourDigits']}"/>
                                <f:param value="#{bundle[restrictionList['optionDesc']]}"/>
                                <f:param value="#{bundle[restrictionList['optionResolutionDesc']]}"/>
                            </h:outputFormat>
     ....
Ritesh
  • 7,472
  • 2
  • 39
  • 43