参数化h:commandButton [英] Parameterize h:commandButton

查看:135
本文介绍了参数化h:commandButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF,我想像h:outputFormat一样参数化命令按钮的文本.

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

类似

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

此刻我是

<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}" [...] >

有任何提示吗?

推荐答案

我们使用JSF 1.2,并在自己的自定义taglib中定义了一个方法.

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)}" >

其中g:我们定义的名称空间.

where g: the name space we have defined.

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

taglib已在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>

,并且该方法在taglib中定义为:

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>

这篇关于参数化h:commandButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆