将消息中的参数从资源包传递到** h:outputFormat **以外的组件 [英] Pass parameters to messages from resource bundle to components other than **h:outputFormat**

查看:84
本文介绍了将消息中的参数从资源包传递到** h:outputFormat **以外的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方便的方法可以将消息中的参数从资源束传递到 h:outputFormat 以外的组件?

Is there a convenient way to pass parameters to messages from resource bundle to components other than h:outputFormat?

例如,这是合法的:

<h:outputFormat value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:outputFormat>

但是我需要一个按钮,就像这样(不起作用):

But I need it for a button, like this (which won't work):

<h:commandButton value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:commandButton>

当然,我可以使用链接而不是按钮,并且可以通过托管bean中的属性来实现它,但是在这个问题中,我正在寻求一种便捷的方法使用按钮...

Of course, I can use link instead of button, and I can make it through a property in a managed bean, but in this question I'm seeking for a convenient way to use the button...

我正在使用RichFaces 3.3.3,JSF2,facelets.

I'm using RichFaces 3.3.3, JSF2, facelets.

推荐答案

这种方法怎么样?

EL表达式使您可以定义函数首先定义EL表达式的功能,该功能接受资源束,其消息关键字和占位符的参数,并输出已解析的消息.

EL expression allow you to define a function .You first define a EL expression 's function , which accepts a resource bundle , its message key and placeholder 's parameter and output the resolved message .

public static String geti18nMsg(ResourceBundle bundle ,String msgKey, String paramValue ) {
    String  msgValue = bundle.getString(msgKey);
    MessageFormat   messageFormat = new MessageFormat(msgValue);
    Object[] args = {paramValue};
    return messageFormat.format(args);
}

然后调用此函数以在<h:commandButton>中获取已解决的消息:

Then call this function to get the resolved message in the <h:commandButton> :

<h:commandButton value="#{f:geti18nMsg(myBundle , parametricMessage, someParameterValue)}"/>

这篇关于将消息中的参数从资源包传递到** h:outputFormat **以外的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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