I want to do something like this:
<display:table name="${summary${index}}">
But it does not work throws exception: "${summary${selChrm}}" contains invalid expression(s). I would like the user to use a drop down list to choose a selection and put in the variable index. Then the table will display the corresponding list of javabean objects, ie. named summary01, summary02, etc. How can I do that? Thanks in advance.
Update: Thanks guys. The problem is with the nested EL. I tried to use
<display:table name="summary${index}">
But nothing shows in the table since summary01 is the variable name. If I hard code the variable name, it will work:
<display:table name="${summary01}">
Therefore, how can I do nested EL? If it is not possibly in JSTL, how can I achieve the behavior that user can use a dropdown list to determine what contents to be display in the table? Thanks again.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
In PowerShell, string concatenation is primarily achieved by using the “+” operator. There are also other ways like enclosing the strings inside double quotes, using a join operator, or using the -f operator. $str1="My name is vignesh."
Use the addition (+) operator to concatenate a string with a variable, e.g. 'hello' + myVar . The addition (+) operator is used to concatenate strings or sum numbers.
You cannot nest EL expressions. You can however just concatenate them.
<display:table name="${summary}${index}">
Or, if ${summary}
is actually not an object in any of the scopes, do
<display:table name="summary${index}">
Update: OK, you actually need to access ${summary01}
. If you know the scope beforehand, then you can access it using the brace notation. Imagine that it's request scoped, you could access it "plain" as follows:
<display:table name="${requestScope['summary01']}">
But you can actually also use another EL variable in the braces (just unquote it):
<display:table name="${requestScope[summary]}">
So, we'd like to set it somewhere. The JSTL c:set
tag is perfectly suitable for this:
<c:set var="summary" value="summary${index}" />
Step one:
<c:set var="summary" value="${requestScope['summary'.concat(index)]}" />
Step two:
<display:table name="${summary}">
Simple as that :)
UPDATE as BalusC mentioned in comments, you need 3.0 Servlets to use this.
This is a thing that really sucks about JSTL: there's no direct way to do that if you want to do it indide a JSTL expression. There's no string concatenation operator, in other words.
You can always do
<something foo='${something} ${something_else}'/>
but that's not always useful.
In my world, I've implemented my own "concat" function, so I can say
$(foo:bar(mystuff:concat("something", something.else))}
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