Parameterize h:commandButton

只谈情不闲聊 提交于 2019-12-11 03:25:59

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/11965432/parameterize-hcommandbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!