I need to create a callback for <h:commandButton>
while as a parameter I need to pass an argument that is string-concatenated with an external parameter id:
I tried nesting an EL expression something like this:
<h:commandButton ... action="#{someController.doSomething('#{id}SomeTableId')}" />
However this failed with an EL exception. What is a right syntax/approach to do this?
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.
6.2. 2 String Concatenation It does not have a specific operator to represent it. Instead, concatenation is performed by writing expressions next to one another, with no operator. For example: $ awk '{ print "Field number one: " $1 }' mail-list -| Field number one: Amelia -| Field number one: Anthony …
Concatenation is the process of combining two or more strings to form a new string by subsequently appending the next string to the end of the previous strings. In Java, two strings can be concatenated by using the + or += operator, or through the concat() method, defined in the java. lang. String class.
2) String Concatenation by concat() method The String concat() method concatenates the specified string to the end of current string. Syntax: public String concat(String another)
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)}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With