Unfortunately, JSF doesn't provide built-in functionality to get what you want, so basically you have three ways to go:
- create a custom EL function to get the substituted value, as described in Pass parameters to messages from resource bundle to components other than h:outputFormat,
- create a custom component that exports the substituted value as a request scope variable visible in EL context, as hinted in How to use Parameterized MessageFormat with non-Value attributes of JSF components or
- use the solution proposed in utility library OmniFaces maintained by BalusC as per the component
<o:outputFormat>
that effectively incorporates in itself the second way.
So, if you are up to the third way, which I personally warmly recommend, the solution is basically as follows:
<o:outputFormat value="#{webCommonMessages['notifications']}" var="t">
<f:param value="1" />
</o:outputFormat>
<h:button value="#{t}" outcome="..." />
Using OmniFaces in a JSF project is ridiculously easy and is descibed on its homepage, but to repeat: just add its jar to /WEB-INF/lib folder of your web application (or include it as a maven dependency) and add a proper namespace in your facelet views, like xmlns:o="http://omnifaces.org/ui"
.
It's also worth adding that my initial answer was wrong. It erroneously assumed that nesting JSF's <h:outputFormat>
will render the necessary HTML element. Still, it is true for a plain navigational link, as provided in JSF by, for example, <h:link>
, and is to be used like:
<h:link outcome="...">
<h:outputFormat value="#{webCommonMessages['notifications']}">
<f:param value="1" />
</h:outputFormat>
</h:link>
You wrongly assumed that <f:param>
nested in <h:button>
will be incorporated in your message from resource bundle. It is used to append query parameters to the generated URL. Instead you need to use <h:outputFormat>
tag for your purpose nested within your button and, thus, not specifying its value
attribute:
<h:button outcome="...">
<h:outputFormat value="#{webCommonMessages['notifications']}">
<f:param value="1" />
</h:outputFormat>
</h:button>