我有使用案例,我必須使用資源束來在UI上顯示各種文本。其中一些資源包條目採用參數(例如{0}),對於這些我使用h:outputFormat,但有時這還不夠。如何使用帶有JSF組件的非Value屬性的參數化MessageFormat
例如
someMessage=Display this message with param {0}
在資源包中。
要顯示它的XHTML我通常做:
<h:outputFormat value="#{msg['someMessage']}"><f:param value="#{someBean.value}"/></h:outputFormat>
行之有效當它是一個簡單的例子,但對於更復雜的使用情況下,它是不夠的。例如,如果我希望commandLink的'title'屬性使用上述資源包條目:
<h:commandLink action="logout" title="#{msg['someMessage']}">
<f:param value="#{someBean.value}" />
<h:graphicImage library="images" name="image.png" />
</h:commandLink>
哪個不起作用。我也嘗試過:
<h:commandLink action="logout">
<f:attribute name="title">
<h:outputFormat value="#{msg['someMessage']}"><f:param value="#{someBean.value}"/></h:outputFormat>
</f:attribute>
<h:graphicImage library="images" name="image.png" />
</h:commandLink>
這也不起作用,因爲f:attibute不允許兒童。
即使存在破解(例如,使用來自primefaces的懸停組件),還有其他可能需要參數化消息的字段。
有誰知道使用MessageFormat的方法,該方法在JSF組件的非值字段中使用參數?
相似的問題:http://stackoverflow.com/questions/5697189/pass-parameters-to-messages-from-resource-bundle-to-components-other-than-hou – Adam 2012-08-17 10:22:48
這是一個不同的問題,因爲那是關於**價值**屬性,這是直接處理(我回答了這個問題)。使用具有**非值**屬性的參數化MessageFormat的方法是我正在尋找的。 – Zak 2012-08-17 16:16:30