2

我目前正在使用 resourceBundle 变量在我的 JSF 代码中获取文本值,例如:

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

有什么方法可以将消息键放入变量中,并将其作为动态参数提供给资源包?我希望能够做这样的事情:

<c:set var="name" value="#{'welcomeMessage'}" />
<h:outputText value="#{resourceBundle.get(name)}" />
4

3 回答 3

1

只需使用一个方法创建一个专用的 ManagedBean,resolveKey(String key)从该方法调用 resourceBundle 查找和查看并使用该 bean。

于 2011-02-24T12:33:18.393 回答
1

使用h:outputFormat,参见示例:http ://www.javabeat.net/tips/47-how-to-use-resource-bundle-in-jsf.html

于 2011-02-24T13:36:34.337 回答
1

资源包采用动态参数。这是我的项目的片段:

    <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>
     ....
于 2011-02-24T15:25:31.990 回答