EL variable in JSF ResourceBundle
Asked Answered
G

1

7

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

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.

Girlhood answered 1/7, 2011 at 11:6 Comment(0)
L
12

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

with

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

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

For more formatting options see thus the MessageFormat API documentation.

Lianne answered 1/7, 2011 at 11:10 Comment(1)
as fast as it could be. Thank you again. What would JSF stackoverflow be without you ;)Girlhood

© 2022 - 2024 — McMap. All rights reserved.