And*_*rey 10 jsf resourcebundle richfaces facelets jsf-2
是否有一种方便的方法将参数传递给从资源包到除h:outputFormat以外的组件的消息?
例如,这是合法的:
<h:outputFormat value="#{myBundle['parametricMessage']}">
<f:param value="#{myBundle['someParameterValue']}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
但我需要一个按钮,像这样(这将无法工作):
<h:commandButton value="#{myBundle['parametricMessage']}">
<f:param value="#{myBundle['someParameterValue']}"/>
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
当然,我可以使用链接而不是按钮,我可以通过托管bean中的属性来实现,但在这个问题中,我正在寻找一种方便的方式来使用按钮...
我正在使用RichFaces 3.3.3,JSF2,facelets.
Ken*_*han 13
这种方法怎么样?
EL表达式允许你定义一个函数.你首先定义一个EL表达式的函数,它接受一个资源包,它的消息键和占位符的参数,并输出已解析的消息.
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);
}
Run Code Online (Sandbox Code Playgroud)
然后调用此函数以获取已解析的消息<h:commandButton>:
<h:commandButton value="#{f:geti18nMsg(myBundle , parametricMessage, someParameterValue)}"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18141 次 |
| 最近记录: |