You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anton Pussep <an...@pussep.de> on 2007/11/18 22:54:55 UTC
concatenate Strings in tag attributes
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Naming convention
Posted by Ted Husted <hu...@apache.org>.
Since it's a psuedo-Friday in the US, and we're chatting about stored
procedures and DBA/Dev range wars, I thought I'd whip out this "oldie
but goodie".
eBay does not use stored procedures
* http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!337.entry
-Ted.
On Nov 21, 2007 1:25 PM, Dave Newton <ne...@yahoo.com> wrote:
> This also depends on how you're accessing the DB: if
> you're using Hibernate, iBatis, etc. then there's a
> convenient layer of abstraction such that the mapping
> from Java method => stored proc need only occur in the
> mapping file(s) and leave code out of it.
>
> Given my underlying mistrust of DB developers I've
> almost always had, or created, a layer between what
> they do and what I do, to the point of having maps of
> interface impls that actually do the DB calls
> (pre-Hibernate days).
>
> d.
>
>
> --- Ted Husted <hu...@apache.org> wrote:
>
> > Given the refactoring tools in IDEs today, I'd
> > probably go with
> > keeping the names in synch as opposed to keeping
> > some other form of
> > documentation in synch; since, if the classes are
> > not named then same,
> > then you might have to otherwise document which
> > class calls which
> > stored procedure.
> >
> > One counter argument might be that "Csm5RRP" doesn't
> > seem like a
> > meaningful name. If it has no meaning in the
> > business domain, then the
> > stored procedure might be considered an
> > implementation detail, better
> > hidden behind a facade. In that case, we might want
> > to give the parser
> > a meaningful name, like QuarterlySalesReport, and
> > let it encapsulate
> > which stored procedure happens to be involved.
> >
> > (Unless of course, the stored procedures were
> > renamed to better
> > describe their function.)
> >
> > -Ted.
> >
> > On Nov 21, 2007 9:35 AM, Zhang, Larry (L.)
> > <lz...@ford.com> wrote:
> > >
> > > I knew my question may not be very related to this
> > list, but let me just
> > > ask anyway:
> > >
> > > I have many DB2 stored procedures, for each
> > procedure I correspondingly
> > > have a Java parser to parser the result set. I
> > currently name these
> > > classes the same name as stored procedure.
> > Example, Csm5RRP (this is the
> > > stored procedure name), then my Java class name is
> > Csm5RRPParser.java.
> > >
> > > Then 2 days ago, they have to change the names for
> > all the stored
> > > procedure, to makes things meaningful, I have to
> > rename all my java
> > > classes. -- this is really a pain.
> > >
> > > Do you guys have an argument on this? Is this a
> > good naming practice? If
> > > not, what will be the naming convention in this
> > situation?
> >
> >
>
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
HTH, Ted <http://www.husted.com/ted/blog/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Naming convention
Posted by Dave Newton <ne...@yahoo.com>.
This also depends on how you're accessing the DB: if
you're using Hibernate, iBatis, etc. then there's a
convenient layer of abstraction such that the mapping
from Java method => stored proc need only occur in the
mapping file(s) and leave code out of it.
Given my underlying mistrust of DB developers I've
almost always had, or created, a layer between what
they do and what I do, to the point of having maps of
interface impls that actually do the DB calls
(pre-Hibernate days).
d.
--- Ted Husted <hu...@apache.org> wrote:
> Given the refactoring tools in IDEs today, I'd
> probably go with
> keeping the names in synch as opposed to keeping
> some other form of
> documentation in synch; since, if the classes are
> not named then same,
> then you might have to otherwise document which
> class calls which
> stored procedure.
>
> One counter argument might be that "Csm5RRP" doesn't
> seem like a
> meaningful name. If it has no meaning in the
> business domain, then the
> stored procedure might be considered an
> implementation detail, better
> hidden behind a facade. In that case, we might want
> to give the parser
> a meaningful name, like QuarterlySalesReport, and
> let it encapsulate
> which stored procedure happens to be involved.
>
> (Unless of course, the stored procedures were
> renamed to better
> describe their function.)
>
> -Ted.
>
> On Nov 21, 2007 9:35 AM, Zhang, Larry (L.)
> <lz...@ford.com> wrote:
> >
> > I knew my question may not be very related to this
> list, but let me just
> > ask anyway:
> >
> > I have many DB2 stored procedures, for each
> procedure I correspondingly
> > have a Java parser to parser the result set. I
> currently name these
> > classes the same name as stored procedure.
> Example, Csm5RRP (this is the
> > stored procedure name), then my Java class name is
> Csm5RRPParser.java.
> >
> > Then 2 days ago, they have to change the names for
> all the stored
> > procedure, to makes things meaningful, I have to
> rename all my java
> > classes. -- this is really a pain.
> >
> > Do you guys have an argument on this? Is this a
> good naming practice? If
> > not, what will be the naming convention in this
> situation?
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Naming convention
Posted by Ted Husted <hu...@apache.org>.
Given the refactoring tools in IDEs today, I'd probably go with
keeping the names in synch as opposed to keeping some other form of
documentation in synch; since, if the classes are not named then same,
then you might have to otherwise document which class calls which
stored procedure.
One counter argument might be that "Csm5RRP" doesn't seem like a
meaningful name. If it has no meaning in the business domain, then the
stored procedure might be considered an implementation detail, better
hidden behind a facade. In that case, we might want to give the parser
a meaningful name, like QuarterlySalesReport, and let it encapsulate
which stored procedure happens to be involved.
(Unless of course, the stored procedures were renamed to better
describe their function.)
-Ted.
On Nov 21, 2007 9:35 AM, Zhang, Larry (L.) <lz...@ford.com> wrote:
>
> I knew my question may not be very related to this list, but let me just
> ask anyway:
>
> I have many DB2 stored procedures, for each procedure I correspondingly
> have a Java parser to parser the result set. I currently name these
> classes the same name as stored procedure. Example, Csm5RRP (this is the
> stored procedure name), then my Java class name is Csm5RRPParser.java.
>
> Then 2 days ago, they have to change the names for all the stored
> procedure, to makes things meaningful, I have to rename all my java
> classes. -- this is really a pain.
>
> Do you guys have an argument on this? Is this a good naming practice? If
> not, what will be the naming convention in this situation?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Naming convention
Posted by Gary Affonso <gl...@greywether.com>.
Zhang, Larry (L.) wrote:
>
> I knew my question may not be very related to this list, but let me just
> ask anyway:
>
> I have many DB2 stored procedures, for each procedure I correspondingly
> have a Java parser to parser the result set. I currently name these
> classes the same name as stored procedure. Example, Csm5RRP (this is the
> stored procedure name), then my Java class name is Csm5RRPParser.java.
>
> Then 2 days ago, they have to change the names for all the stored
> procedure, to makes things meaningful, I have to rename all my java
> classes. -- this is really a pain.
>
> Do you guys have an argument on this? Is this a good naming practice? If
> not, what will be the naming convention in this situation?
About the only thing people seem to 100% agree upon about naming
conventions is that you should probably have one, that you should
document it if you do, and that if you have one, STICK TO IT.
As to what that convention is, you'll see a ton of debate. Personally,
I think your naming convention is fine.
As for the fact that the sprocs have changed names, I'd change the names
of the java classes so they match the new names. Again, if you've got a
naming convention, STICK TO IT. Sometimes sticking to it causes more work.
Oh yah, and let your sproc guys know that you're syncing your Class
names to their sproc names and that name changes adversely effect you.
They should know when they make more work for you. Might not change any
behavior on their part, but communication is rarely a bad idea.
As for the name change...
Your IDE should make a Classname-refactor pretty easy. Just be sure to
double-check files the IDE might not reach (like Struts XML Action
definitions and the Spring context xml, etc.)
And if you're not using an IDE that makes refactoring easy... Go get an
IDE that makes refactoring easy! (NetBeans, Eclipse, IntelliJ all have
built-in refactoring support that will do the above easily).
And if you have a unit-test suite (you do, right?) running after the
refactor should give you great confidence that all is working fine
again. That's one of the huge benefits of a test suite, takes a lot of
the "hope and pray" out of a refactor.
My $.02.
- Gary
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Naming convention
Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
I knew my question may not be very related to this list, but let me just
ask anyway:
I have many DB2 stored procedures, for each procedure I correspondingly
have a Java parser to parser the result set. I currently name these
classes the same name as stored procedure. Example, Csm5RRP (this is the
stored procedure name), then my Java class name is Csm5RRPParser.java.
Then 2 days ago, they have to change the names for all the stored
procedure, to makes things meaningful, I have to rename all my java
classes. -- this is really a pain.
Do you guys have an argument on this? Is this a good naming practice? If
not, what will be the naming convention in this situation?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Gary Affonso <gl...@greywether.com>.
Anton Pussep wrote:
>> value="%{'/jsp/'+#parameters.file[0]}"
>
> I thought I tried that one out already, but apparently I remembered
> wrong, since it really works, which is great!
>
> Anyway, for my part this is very inconvenient. Also I don't know a way
> to pass an array to request parameters. Thus IMHO there should be a more
> convenient way to concatenate strings here.
When you use the raw request parameters, the datatype is determined by
the Servlet engine. It's a *array* of strings because HTML forms can
have more than one value associated with a given field. Checkboxes are
the typical example, but keep in mind that *most* form field types
(select, text, etc.) can have more than one control with the same name
which yields multiple values associated .
So when form data is submitted, the servlet engine has to handle that
case. This is why the raw parameter data is a string array.
Now, for you this is "inconvenient", you almost probably have just one
value submitted for the "file" parameter.
So my suggestion is do *not* access the raw parameters. That's sort of
not the point of S2 anyway. The idea is to let S2 translate the raw
input values submitted from the form into property values either on the
action itself, or on an object/bean that the action makes available.
So instead of doing:
value="%{'/jsp/'+#parameters.file[0]}"
You should probably be doing something like:
In the form
-----------
<input type="foo" name="targetFileName" />
In the Action
-------------
private String targetFilename
public void setTargetFilename(tf){this.targetFilename = tf; }
public String getTargetFilename(){retrun this.targetFilename; }
In the View
-----------
value="%{'/jsp/' + targetFileName}"
The idea here is that you have an action property for the form field.
As long as the names are the same (and you provide a setter) S2 will
automatically get the value from the submitted form and get it into the
action's property.
And as long as you have a getter, you can reference that value in the
view by simply referencing the property name.
That way you don't deal with the fact that the raw request data is an
array. S2 has done the translation for you from an array of Strings to
a single string when it sets the property value.
- Gary
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Anton Pussep <an...@pussep.de>.
> value="%{'/jsp/'+#parameters.file[0]}"
I thought I tried that one out already, but apparently I remembered
wrong, since it really works, which is great!
Anyway, for my part this is very inconvenient. Also I don't know a way
to pass an array to request parameters. Thus IMHO there should be a more
convenient way to concatenate strings here.
Thanks,
Anton
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Dave Newton <ne...@yahoo.com>.
The issue seems to be that OGNL's expression parsing
does different things at different times.
>>>>> <s:text name="/jsp/%{#parameters.file}" />
>>>>>
>>>>> prints out "/jsp/test.jsp", whereas
>>>>>
>>>>> <s:set name="a" value="'/jsp/' +
#parameters.file" />
> >>>>> prints out "/jsp/[Ljava.lang.String;@1bd2184",
This is, perhaps, related to the thread from a week or
two ago, the "Re: OGNL struts property" thread [1]
where the OGNL expression's construction impacts type
information.
d.
[1]
http://www.nabble.com/OGNL-struts-property-tf4770568.html#a13664415
--- Gary Affonso <gl...@greywether.com> wrote:
> 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="%{@org.apache.commons.lang@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?
> >>>>>
>
=== message truncated ===
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Gary Affonso <gl...@greywether.com>.
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="%{@org.apache.commons.lang@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: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>> --------------------------------
>>>>> 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: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Anton Pussep <an...@pussep.de>.
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="%{@org.apache.commons.lang@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: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>> --------------------------------
>>>> 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: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
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="%{@org.apache.commons.lang@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: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>> --------------------------------
>>> 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: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Anton Pussep <an...@pussep.de>.
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: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> --------------------------------
>> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: concatenate Strings in tag attributes
Posted by Saul Qunming Yuan <yu...@dataanvil.com>.
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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> --------------------------------
> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org