How to use Parameterized MessageFormat with non-Value attributes of JSF components

前端 未结 1 2065
无人及你
无人及你 2020-12-06 18:04

I have use case in which I have to use resource bundle to display various texts on UI. Some of these resource bundle entries take paramets (e.g. {0}), for these I use h:outp

相关标签:
1条回答
  • 2020-12-06 18:06

    You could create a custom EL function for this with which you can ultimately end up like:

    <h:commandLink ... title="#{my:format(msg['someMessage'], someBean.value)}" />
    

    You can use the MessageFormat API to perform the job, exactly as <h:outputFormat> is doing under the covers.

    An alternative is to create a custom component which does the same as JSTL's good 'ol <fmt:message> which supports a var attribute to export the formatted message into the EL scope.

    <my:outputFormat ... var="linkTitle">
        ...
    </my:outputFormat>
    <h:commandLink ... title="#{linkTitle}" />
    

    Update: JSF utility library OmniFaces has #{of:formatX()} functions and a <o:outputFormat> component for the very purpose.

    0 讨论(0)
提交回复
热议问题