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

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.

Leave a Comment