JSF ResourceBundle中的EL变量 [英] EL variable in JSF ResourceBundle
问题描述
我读到某个地方(不再找到它),可以在资源包中使用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,000
或1.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屋!