JSF ResourceBundle中的EL变量 [英] EL variable in JSF ResourceBundle

查看:110
本文介绍了JSF ResourceBundle中的EL变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到某个地方(不再找到它),可以在资源包中使用EL Expresions,然后在不更改* .xhtml文件的情况下使用它.

i read somewhere (don't find it anymore) that i can use EL Expresions in the resource bundle and then use it without changes in *.xhtml files.

some.text=#{someBean.stepsLeft} more

以不同的语言切换变量的位置.但实际上它无法正常工作. 我可以使用Interpolator类来处理解析,也可以在some.text.after之后添加some.text.before并让其中之一为空.如果可能的话,我希望它在不使用interpolator.interpolate()的情况下使用它.

to switch the position of the variable in different languages. But actually it wont work. I can use Interpolator class to handle the parsing or add some.text.before some.text.after and let one of them empty. I would prefer it to use it without interpolator.interpolate() if possible.

推荐答案

JSF resourcebundles在默认情况下不会解析EL.但是,默认情况下它支持 MessageFormat API <h:outputFormat> <f:param>

JSF resourcebundles does by default not resolve EL. It however by default supports MessageFormat API in combination with <h:outputFormat> and <f:param>.

some.text = {0} more

使用

<h:outputFormat value="#{i18n['some.text']}">
    <f:param value="#{someBean.stepsLeft}" />
</h:outputFormat>

您甚至可以明确地将其设置为number类型,例如根据视图区域设置,1000将显示为1,0001.000.

You can even explicitly make it a number type so that e.g. 1000 will be displayed as 1,000 or 1.000 depending on the view locale.

some.text = {0,number} more

有关更多格式设置选项,请参见 MessageFormat API文档.

For more formatting options see thus the MessageFormat API documentation.

这篇关于JSF ResourceBundle中的EL变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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