I don't have the full solution, but lets think about this for a moment
instead of using trial-and-error...
By default, every struts2 tag either expects the attribute to be a
string literal, an OGNL expression evaluated as a string or an OGNL
expression evaluated as an object.
We don't really know which without checking the docs or code, but as
we're performing an operation we can take the safe path state that we're
using an OGNL expression.
<s:set name="a" value="%{insert_expression}" />
Now that we know we're using an expression we discount all the attempts
that aren't valid OGNL and write some OGNL to concatenate a string
<s:set name="a" value="%{'/jsp/'+#parameters.file}" />
ie. a string literal concatenated to the root object parameters' member
named file
You said you tried this and got:
"/jsp/[Ljava.lang.String;@1bd2184"
The concatenation has worked, but it evaluated #parameters.file as an
object reference rather than a string. Now you've isolated the problem
to this sub-expression.
That sucks, so now think of a way to instruct it that we want to value
to be evaluated as a string.
Does <s:set name="a" value="%{#parameters.file}" /> work? It should, so
the problem is specific to the concatenation operation.
Maybe we need to force evaluation of a string prior to concatenation
(haven't tried this:)
<s:set name="a" value="%{'/jsp/'+#parameters.file.toString()}" />
ie. call toString() prior to concatentation. One of two things will
happen: it will work because the result is strongly-type as a string, or
it will concatenate another reference to a string object
If that doesn't work, at this stage I'd search JIRA for a known problem
and resort to something more reliable like calling a static method
<s:set name="a" value="[EMAIL PROTECTED]@concatenate('/jsp/', #parameters.file)}"
/>
Hope that helps,
Jeromy Evans
PS: s:text evaluates the name attribute as a string,whereas s:set
evaluates the value attribute as an object. This accounts for the
different behaviour. I find this inconsistency between tags is one of
the most frustrating aspects of how OGNL is used by struts2.
Anton Pussep wrote:
Results in the same as
<s:set name="a" value="'/jsp/'#parameters.file" />
which means that a remains unset.
Same for:
<s:set name="a" value="/jsp/%{#parameters.file}" />
<s:set name="a" value="'/jsp/'%{#parameters.file}" />
<s:set name="a" value="%{/jsp/#parameters.file}" />
<s:set name="a" value="%{'/jsp/'#parameters.file}" />
Best,
Anton
Saul Qunming Yuan wrote:
Hi
You may want to try the following to set variable "a":
<s:set name="a">
<s:text name="/jsp/%{#parameters.file}" />
</s:set>
just a thought.
Saul
Anton Pussep wrote:
Hello,
I am trying to concatenate strings in tag attributes and get results
that I don't understand:
<s:text name="/jsp/%{#parameters.file}" />
prints out "/jsp/test.jsp", whereas
<s:set name="a" value="'/jsp/' + #parameters.file" />
<s:text name="#a" />
prints out "/jsp/[Ljava.lang.String;@1bd2184", same for
<s:set name="a" value="%{'/jsp/' + #parameters.file}" />
whereas the following does not work:
<s:set name="a" value="'/jsp/'#parameters.file" />
What is the way to concatenate strings in the set tag and why doesn't it
work the same way as it does in the text tag?
Best,
Anton
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------
Spam/Virus scanning by CanIt Pro
For more information see
http://www.kgbinternet.com/SpamFilter.htm
To control your spam filter, log in at
http://filter.kgbinternet.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]