0
votes

I would like to display an internationalized message in the place holder below. All examples I'm hitting, work with a message bundle defined in faces-config and simply use that bundle name. But that works only when we know what message key to use. This isn't the case here.

Consider this basic example:

<h:dataTable border="1" value="#{indexBean.webAdminCatalogList}" var="menuItem">
    <h:column>#{message key here}</h:column>
</h:dataTable>

The code above loops through a list. Each menuItem variable contains a titleMessageCode which corresponds to a field in the bundle properties files. How do you go about fetching a message using menuItem.titleMessageCode? Is there a special JSF tag or are such internationalized labels prepared when constructing the bean?

1

1 Answers

1
votes

You can use the brace notation #{map[dynamicKey]} to use a dynamic variable as map key. Given a bundle name of text, here's an example:

<h:dataTable border="1" value="#{indexBean.webAdminCatalogList}" var="menuItem">
    <h:column>#{text[menuItem.titleMessageCode]}</h:column>
</h:dataTable>

Note that this is not specific to JSF, but to EL. Those #{} things are not part of JSF, they are part of EL (Expression Language). JSF just happens to make use of it. See also our EL wiki page.