How to concatenate Strings in EL expression?

If you’re already on EL 3.0 (Java EE 7; WildFly, Tomcat 8, GlassFish 4, etc), then you could use the new += operator for this:

<h:commandButton ... action="#{someController.doSomething(id += 'SomeTableId')}" />

If you’re however not on EL 3.0 yet, and the left hand is a genuine java.lang.String instance (and thus not e.g. java.lang.Long), then use EL 2.2 capability of invoking direct methods with arguments, which you then apply on String#concat():

<h:commandButton ... action="#{someController.doSomething(id.concat('SomeTableId'))}" />

Or if you’re not on EL 2.2 yet, then use JSTL <c:set> to create a new EL variable with the concatenated values just inlined in value:

<c:set var="tableId" value="#{id}SomeTableId" />
<h:commandButton ... action="#{someController.doSomething(tableId)}" />

See also:

Leave a Comment