I'm currently working with Struts2 (inexperienced developer) and I've been searching but I couldn't find how to apply an OGNL expression to a variable stored in context.
The thing is that I need to retrieve a parameter from Context and uppercase it. By now, I've tried to do it this way but sadly with no luck:
<s:property value="#myVar.toUpperCase()" />
As this works with variables stored in the ValueStack (notation without #), I don't really understand why this won't work with anything stored in Context..
I'm able to print the #myVar
content just fine if I don't append the .toUpperCase()
to it.
Also tried this workaround but didn't help:
<s:property value="<s:property value="#myVar"/>.toUpperCase()"/>
So what's the thing I'm missing? How can I apply an OGNL expression to a variable stored in Context?
Your variable most probably isn't a String so there isn't
toUpperCase()
method in it. The solution is to calltoString()
before callingtoUpperCase()
.Update
Actually your problem is here
<s:set var="myVar" value="%{#parameters.myVar}"/>
since there could be more then onemyVar
in parameters it will return an array of Strings, so if you want just a single parameter change your expression to#parameters.myVar[0]
and thentoUpperCase()
will work.OR