Matteo
Matteo

Reputation: 14930

Parameterize h:commandButton

I am using JSF and I would like to parameterize the text of a command button similarly to h:outputFormat.

Something like

<h:commandButton value="Text {0} some more text" [...] >

At the moment I am

<h:commandButton value="Text #{bean.value()} some more text" [...] >

but this makes me split all the texts stored as properties in two each time I have a parameter

<h:commandButton value="#{msg.textbefore} #{bean.value()} #{msg.textafter}" [...] >

Any hint?

Upvotes: 2

Views: 373

Answers (1)

Bharat Sinha
Bharat Sinha

Reputation: 14363

We make use of JSF 1.2 and we have defined a method in our own custom taglib.

<h:commandButton value="#{g:formatMessage('Text {0} some more text', bean.value)}" >

where g: the name space we have defined.

xmlns:g="http://www.client.com/product"

The taglib is registered in web.xml

<context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>
        PATH_TO_CUSTOM_TAGLIB;/WEB-INF/tomahawk.taglib.xml;
    </param-value>
</context-param>

and the method is defined in the taglib as:

<function>
    <function-name>formatMessage</function-name>
    <function-class>com.XXX.XXX.XXX.JavaClass</function-class>
    <function-signature>java.lang.String formatMessage(java.lang.String, java.lang.String)</function-signature>
</function>

Upvotes: 1

Related Questions