'#' character before EL expression used inside a JSTL tag behaves strangely
Question
I have the following code to set a userId variable:
(userId set in prior code)
<c:set var="userId" value="(Cust#${userId})" />
Which produces the following string: (Cust#${userId})
The following code works as expected, however:
<c:set var="userId" value="(Cust# ${userId})" />
displays the following string (Cust# 0001) .
Why does the '#' character before a '${string}' expression prevent the string from being evaluated? Is there a work around I could use that doesnt involve having to insert a space?
Solution
Since JSF would use:
#{userId}
To return a user Id, I would venture to guess that this is either a bug or expected behavior caused by the # sign making the parser unhappy. Just use either of:
<c:set var="userId" value="(Cust#${userId})" />
<c:set var="userId" >(Cust#${userId})</c:set>
OTHER TIPS
I tested the above and it does not work. Its ouput would be:
Cust#0002 or whatever.
You can use an escape to get it to work right though. For example:
<c:set var="userId" value="(Cust\#${userId})" />
The output is:
Cust#0002