0

In my ResourceBundle i have entries like these:

datasourcegroup.KUNDEN=Kunden
datasourcegroup.INKASSO=Inkasso
datasourcegroup.INTERESSENTEN=Interessenten
datasourcegroup.WARN=Warnadressen

The uppercase parts of the keynames are actually the values of a related Enum type:

public enum DatasourceGroup {
    KUNDEN,
    INKASSO,
    INTERESSENTEN,
    WARN;
}

Now in my Facelets pages i would like to access these entries, which is not a problem if i do it with a static keyname, like here:

<h:outputText value="#{msg['datasourcegroup.KUNDEN']}" />

But what i really would like to do is to get the uppercase part of the keyname from a variable, so "semantically" it would be something like this:

<h:outputText value="#{msg['datasourcegroup.#{sessionBean.datasourceGroup}']}" />

But as i learned this is not possible, because EL expressions can't be nested.

Any advice how i could approach this?

Thanks in advance!

regards Mario

EDIT this is the solution i went with:

public String getDatasourceGroupLabel(DatasourceGroup group) {
    return "datasourcegroup."+group.toString();
}


<h:outputText value="#{msg[sessionBean.getDatasourceGroupLabel(group)]}" />
Mario Köhler
  • 192
  • 1
  • 10
  • You cannot nest EL, but you **can** concatenate strings in a javamethod or via [EL](http://stackoverflow.com/questions/3640254/string-concatenation-in-el). Just make sure the [escaping of the 'single quotes'](http://stackoverflow.com/questions/33019729/escape-javascript-quotes-in-el-in-a-jsf-component-attribute) is done correctly . So something like `#{msg['\''datasource.'.concat(sessionBean.datasourceGroup).concat('\'']') }` or `#{msg[sessionBean.concatenateDatasourceGroup]}` where the latter returns `'datasourcegroup.KUNDEN'` (both code snippets not tested) will work – Kukeltje Apr 10 '17 at 09:03
  • Thank you! I got it working with the second method. the first one didn't work for me and i couldn't figure out how to fix it. the single-quote-escapes made my head whirl :-) ... – Mario Köhler Apr 10 '17 at 10:17

0 Answers0