String concatenation in EL for dynamic ResourceBundle key

If you’re already on Servlet 3.1 / EL 3.0 (Tomcat 8, WildFly 8, GlassFish 4, etc), make use of new EL 3.0 += operator:

<h:outputText value="#{msg['entry' += managedBean.entryIndex]}" />

If you’re only on Servlet 3.0 / EL 2.2 (Tomcat 7, JBoss AS 6/7, GlassFish 3, etc), make use of new EL 2.2 ability to directly invoke methods such as String#concat():

<h:outputText value="#{msg['entry'.concat(managedBean.entryIndex)]}" />

If you’re even not on Servlet 3.0 / EL 2.2 yet, make use of <c:set> to create another variable with the desired EL expression inlined:

<c:set var="key" value="entry#{managedBean.entryIndex}" />
<h:outputText value="#{msg[key]}" />

Leave a Comment