Looks to me like the return value of parameters.file is *not* a String. It's a an *array* of strings. And a toString() on an Array of strings looks exactly like what you're seeing:

  [Ljava.lang.String;...

(the prefixed "[" is the clue that it's a string *array*).

If the "file" parameter has only 1 element (as it sounds like you're assuming) then you want element 0 of that array, so I think you want something like this...

  value="%{'/jsp/'+#parameters.file[0]}"

- Gary

Anton Pussep wrote:
First of all thanks a lot for the good and well structured reply. I tried

<s:set name="a" value="%{'/jsp/'+#parameters.file.toString()}" />

but the result is still the same. I also wrote an own static method that
prints out the result and it is also "/jsp/[Ljava.lang.String;@1bd2184".
However, a static concatenation method will most probably work, but I
hope it is not the only way to do it.

In JIRA I only found a three year old issue asking for the concatenation
via "+" in the property tag. I cannot imagine String concatenation not
being supported. I am going to create a JIRA issue for that tomorrow,
unless someone can tell me another way than using a static concatenation
method.

Best,
Anton

Jeromy Evans wrote:
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]





---------------------------------------------------------------------
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]

Reply via email to