You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by crappycrumpet <pa...@hotmail.com> on 2008/08/22 05:46:57 UTC
Struts 2.0.11 from 2.0.9 EL Expression problem
Hi All,
I know EL Expression has been disabled from 2.0.10 on. Unfortunately I have
some jsp has uses EL.
I have this jsp files that renders a generic dropdown box that looks like
the following.
<s:select name="%{fieldName}"
list='list'
listKey='${listKey}'
listValue='${listValue}'
multiple='true'
size='8'
required="%{required}"
/>
So the action that uses this would have a list of objects and a listKey
field that contains a string saying for example "id" and a listValue string
saying for example "name" and the select drop would be shown with the list
of object's id and it's name value for display.
This however no longer works after updating to 2.0.11.2. Substituting ${}
with %{} only end it putting the literal value (e.g. "id" and "name") in the
drop down box's value and display value. Any idea how I can work around
this?
Cheers.
--
View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19100876.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Gabriel Belingueres <be...@gmail.com>.
Wow what was I drinking last night? :-P
I extracted some examples from when I had to convert one app from
2.0.9 to 2.0.11:
1) If the variable is in request scope:
From: onclick="this.form.action = '${urlsubmit}';"/>
To: onclick="this.form.action = '%{#request['urlsubmit']}'" />
(or use #attr instead of #request if you want)
(or use #parameters to replace the JSTL's param)
2) More complicated expression:
From: disabled="${empty SetAfiliaciones || criterio.idcampania == 0}"
To: disabled="%{#session['SetAfiliaciones'] == null ||
#session['SetAfiliaciones'].isEmpty() ||
#request['criterio'].idcampania == 0}"
3) You may want to convert from OGNL to JSTL too (because changing the
tag prefix is easier than changing the expression):
From: <s:if test="${empty x || !empty y && ...}">
To: <c:if test="${empty x || !empty y && ...}">
4) Some times you can avoid the conversion altogether:
From: <s:param name="x" value="%{'${someX}'}" />
To: <s:param name="x">${someX}</s:param>
Regarding your actual requirement of writing a "dynamic" select tag, I
see no difference at all with the previous version. Instead of
<s:select name="${param.fieldName}"
write:
<s:select name='%{#parameters["fieldName"]}'
and so on
2008/8/26, Dave Newton <ne...@yahoo.com>:
> --- On Mon, 8/25/08, crappycrumpet wrote:
> > Hence I was wondering how I can work around it.
>
> Modify the TLD.
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 8/25/08, crappycrumpet wrote:
> Hence I was wondering how I can work around it.
Modify the TLD.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by crappycrumpet <pa...@hotmail.com>.
Yes exactly!!! Hence I was wondering how I can work around it. I guess I'll
have to roll back or write my own select thing iterating through the list
and doing (listKey)([0]), (listValue)([0]) :(. My god I wish I understand
what select.ftl is doing.
(FYI, the OGNL conversion section says "todo" :) In this case it's not quite
as straight-forward, though, since the OP was *relying* on the ability to
have the expression pre-evaluated before it hit OGNL.
--
View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19155379.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Dave Newton <ne...@yahoo.com>.
(FYI, the OGNL conversion section says "todo" :) In this case it's not quite as straight-forward, though, since the OP was *relying* on the ability to have the expression pre-evaluated before it hit OGNL.
Dave
--- On Mon, 8/25/08, Gabriel Belingueres <be...@gmail.com> wrote:
> From: Gabriel Belingueres <be...@gmail.com>
> Subject: Re: Struts 2.0.11 from 2.0.9 EL Expression problem
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Monday, August 25, 2008, 9:08 PM
> Please note that from S2 2.0.11.x it is illegal to call
> Struts tags
> using EL expressions in tag attributes [1], you only can
> use OGNL
> expressions. Upgrading should be a straightforward step
> [2].
>
> [1]
> http://struts.apache.org/2.0.11.2/docs/release-notes-2011.html
> [2]
> http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-ConvertELexpressionstoOGNL
>
> 2008/8/25 crappycrumpet <pa...@hotmail.com>:
> >
> > Yes the select code was meant to be a generic select
> where I can just bung it
> > in the struts.xml for different Action classes that
> has the values for
> > fieldName, list (vector of object), listKey, listValue
> so that I can just
> > make select dropdowns without making more coding. So
> when I make assorted
> > form pages which has a dog dropdown for example I can
> put in field name
> > required for that form dogId or altDogId and it would
> use the same action to
> > generate the dropdown.
> >
> > Here my DogAction as an example.
> > http://www.nabble.com/file/p19153375/DogAction.java
> DogAction.java
> >
> > Here's my dog object.
> > http://www.nabble.com/file/p19153375/Dog.java Dog.java
> >
> > And my action config in struts.xml:
> > <package name="pet"
> extends="petshop" namespace="/pet">
> > <action name="dog_select"
> method="doGetList"
> >
> class="com.petshop.struts.actions.DogAction">
> > Dog
> > id
> > name
> > false
> > <result
> type="tiles">widget.generic_select</result>
> > </action>
> > </package>
> >
> > Then I can all it like this:
> >
> https://localhost/petshop/pet/dog_select.do?fieldName=dogId&defaultValue=0&defaultName=All&required=false&theme=filter&debug=console
> >
> > Here is my generic_select.jsp that used to work in
> struts 2.0.9:
> > <%@ taglib prefix="s"
> uri="/struts-tags" %>
> >
> > <s:if test="param.fieldName" >
> > <s:if test="multiple" >
> > <s:select
> name="${param.fieldName}"
> > list='list'
> > listKey='${listKey}'
> > listValue='${listValue}'
> > multiple='true'
> >
> onchange="dojo.event.topic.publish('${param.fieldName}',
> > {dropdown:this})"
> > size='8'
> > required="${param.required}"
> > />
> > </s:if>
> > <s:else>
> > <s:select
> name="${param.fieldName}"
> > list='list'
> > listKey='${listKey}'
> > listValue='${listValue}'
> >
> headerKey="${param.defaultValue}"
> >
> headerValue="${param.defaultName}"
> >
> onchange="dojo.event.topic.publish('${param.fieldName}',
> > {dropdown:this})"
> > required="${param.required}"
> > />
> > </s:else>
> > </s:if>
> > <s:else>
> > <s:select name="${fieldName}"
> > label="${label}"
> > list='list'
> > listKey='${listKey}'
> > listValue='${listValue}'
> > headerKey="${param.defaultValue}"
> > headerValue="${param.defaultName}"
> >
> onchange="dojo.event.topic.publish('${fieldName}',
> > {dropdown:this})"
> > required="${param.required}"
> > theme="${param.theme}"
> > />
> > </s:else>
> >
> > And finally my tile.xml setting for generic select:
> > <definition name="widget.generic_select"
> > template="/tiles/generic_select.jsp"/>
> > --
> > View this message in context:
> http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19153375.html
> > Sent from the Struts - User mailing list archive at
> Nabble.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: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Gabriel Belingueres <be...@gmail.com>.
Please note that from S2 2.0.11.x it is illegal to call Struts tags
using EL expressions in tag attributes [1], you only can use OGNL
expressions. Upgrading should be a straightforward step [2].
[1] http://struts.apache.org/2.0.11.2/docs/release-notes-2011.html
[2] http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-ConvertELexpressionstoOGNL
2008/8/25 crappycrumpet <pa...@hotmail.com>:
>
> Yes the select code was meant to be a generic select where I can just bung it
> in the struts.xml for different Action classes that has the values for
> fieldName, list (vector of object), listKey, listValue so that I can just
> make select dropdowns without making more coding. So when I make assorted
> form pages which has a dog dropdown for example I can put in field name
> required for that form dogId or altDogId and it would use the same action to
> generate the dropdown.
>
> Here my DogAction as an example.
> http://www.nabble.com/file/p19153375/DogAction.java DogAction.java
>
> Here's my dog object.
> http://www.nabble.com/file/p19153375/Dog.java Dog.java
>
> And my action config in struts.xml:
> <package name="pet" extends="petshop" namespace="/pet">
> <action name="dog_select" method="doGetList"
> class="com.petshop.struts.actions.DogAction">
> Dog
> id
> name
> false
> <result type="tiles">widget.generic_select</result>
> </action>
> </package>
>
> Then I can all it like this:
> https://localhost/petshop/pet/dog_select.do?fieldName=dogId&defaultValue=0&defaultName=All&required=false&theme=filter&debug=console
>
> Here is my generic_select.jsp that used to work in struts 2.0.9:
> <%@ taglib prefix="s" uri="/struts-tags" %>
>
> <s:if test="param.fieldName" >
> <s:if test="multiple" >
> <s:select name="${param.fieldName}"
> list='list'
> listKey='${listKey}'
> listValue='${listValue}'
> multiple='true'
> onchange="dojo.event.topic.publish('${param.fieldName}',
> {dropdown:this})"
> size='8'
> required="${param.required}"
> />
> </s:if>
> <s:else>
> <s:select name="${param.fieldName}"
> list='list'
> listKey='${listKey}'
> listValue='${listValue}'
> headerKey="${param.defaultValue}"
> headerValue="${param.defaultName}"
> onchange="dojo.event.topic.publish('${param.fieldName}',
> {dropdown:this})"
> required="${param.required}"
> />
> </s:else>
> </s:if>
> <s:else>
> <s:select name="${fieldName}"
> label="${label}"
> list='list'
> listKey='${listKey}'
> listValue='${listValue}'
> headerKey="${param.defaultValue}"
> headerValue="${param.defaultName}"
> onchange="dojo.event.topic.publish('${fieldName}',
> {dropdown:this})"
> required="${param.required}"
> theme="${param.theme}"
> />
> </s:else>
>
> And finally my tile.xml setting for generic select:
> <definition name="widget.generic_select"
> template="/tiles/generic_select.jsp"/>
> --
> View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19153375.html
> Sent from the Struts - User mailing list archive at Nabble.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: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by crappycrumpet <pa...@hotmail.com>.
Yes the select code was meant to be a generic select where I can just bung it
in the struts.xml for different Action classes that has the values for
fieldName, list (vector of object), listKey, listValue so that I can just
make select dropdowns without making more coding. So when I make assorted
form pages which has a dog dropdown for example I can put in field name
required for that form dogId or altDogId and it would use the same action to
generate the dropdown.
Here my DogAction as an example.
http://www.nabble.com/file/p19153375/DogAction.java DogAction.java
Here's my dog object.
http://www.nabble.com/file/p19153375/Dog.java Dog.java
And my action config in struts.xml:
<package name="pet" extends="petshop" namespace="/pet">
<action name="dog_select" method="doGetList"
class="com.petshop.struts.actions.DogAction">
Dog
id
name
false
<result type="tiles">widget.generic_select</result>
</action>
</package>
Then I can all it like this:
https://localhost/petshop/pet/dog_select.do?fieldName=dogId&defaultValue=0&defaultName=All&required=false&theme=filter&debug=console
Here is my generic_select.jsp that used to work in struts 2.0.9:
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:if test="param.fieldName" >
<s:if test="multiple" >
<s:select name="${param.fieldName}"
list='list'
listKey='${listKey}'
listValue='${listValue}'
multiple='true'
onchange="dojo.event.topic.publish('${param.fieldName}',
{dropdown:this})"
size='8'
required="${param.required}"
/>
</s:if>
<s:else>
<s:select name="${param.fieldName}"
list='list'
listKey='${listKey}'
listValue='${listValue}'
headerKey="${param.defaultValue}"
headerValue="${param.defaultName}"
onchange="dojo.event.topic.publish('${param.fieldName}',
{dropdown:this})"
required="${param.required}"
/>
</s:else>
</s:if>
<s:else>
<s:select name="${fieldName}"
label="${label}"
list='list'
listKey='${listKey}'
listValue='${listValue}'
headerKey="${param.defaultValue}"
headerValue="${param.defaultName}"
onchange="dojo.event.topic.publish('${fieldName}',
{dropdown:this})"
required="${param.required}"
theme="${param.theme}"
/>
</s:else>
And finally my tile.xml setting for generic select:
<definition name="widget.generic_select"
template="/tiles/generic_select.jsp"/>
--
View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19153375.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Gabriel Belingueres <be...@gmail.com>.
The select documentation [1] shows perfectly valid uses of the tag.
Yours:
<s:select name="%{fieldName}"
list='list'
listKey='${listKey}'
listValue='${listValue}'
multiple='true'
size='8'
required="%{required}"
/>
Why the name parameter has a %{}? Do you intend to give a different
name to the select at runtime?
Is the 'list' really a java.util.List? or is it a Map?
Please post you page and action code to provide you more help.
[1] http://struts.apache.org/2.1.2/docs/select.html
2008/8/24, crappycrumpet <pa...@hotmail.com>:
>
> Hi Gabriel,
>
> I tried that already and just gives me "name" for listValue and "id" for
> listKey (as in the select box would be filled with literally the string 'id'
> for value and 'name' for the display value :( ).
>
> is there an ognl expression that I can use so that it evaluates the result
> again?
>
> Thanks for the reply!
>
> cheers.
>
>
> Gabriel Belingueres-2 wrote:
> >
> > try using neither ${} nor %{}:
> >
> > listKey='listKey'
> > listValue='listValue'
> >
> > 2008/8/22, crappycrumpet <pa...@hotmail.com>:
> >>
> >> Hi All,
> >>
> >> I know EL Expression has been disabled from 2.0.10 on. Unfortunately I
> >> have
> >> some jsp has uses EL.
> >> I have this jsp files that renders a generic dropdown box that looks like
> >> the following.
> >>
> >> <s:select name="%{fieldName}"
> >> list='list'
> >> listKey='${listKey}'
> >> listValue='${listValue}'
> >> multiple='true'
> >> size='8'
> >> required="%{required}"
> >> />
> >>
> >> So the action that uses this would have a list of objects and a listKey
> >> field that contains a string saying for example "id" and a listValue
> >> string
> >> saying for example "name" and the select drop would be shown with the
> >> list
> >> of object's id and it's name value for display.
> >>
> >> This however no longer works after updating to 2.0.11.2. Substituting ${}
> >> with %{} only end it putting the literal value (e.g. "id" and "name") in
> >> the
> >> drop down box's value and display value. Any idea how I can work around
> >> this?
> >>
> >> Cheers.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19100876.html
> >> Sent from the Struts - User mailing list archive at Nabble.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
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19136189.html
> Sent from the Struts - User mailing list archive at Nabble.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: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by crappycrumpet <pa...@hotmail.com>.
Hi Gabriel,
I tried that already and just gives me "name" for listValue and "id" for
listKey (as in the select box would be filled with literally the string 'id'
for value and 'name' for the display value :( ).
is there an ognl expression that I can use so that it evaluates the result
again?
Thanks for the reply!
cheers.
Gabriel Belingueres-2 wrote:
>
> try using neither ${} nor %{}:
>
> listKey='listKey'
> listValue='listValue'
>
> 2008/8/22, crappycrumpet <pa...@hotmail.com>:
>>
>> Hi All,
>>
>> I know EL Expression has been disabled from 2.0.10 on. Unfortunately I
>> have
>> some jsp has uses EL.
>> I have this jsp files that renders a generic dropdown box that looks like
>> the following.
>>
>> <s:select name="%{fieldName}"
>> list='list'
>> listKey='${listKey}'
>> listValue='${listValue}'
>> multiple='true'
>> size='8'
>> required="%{required}"
>> />
>>
>> So the action that uses this would have a list of objects and a listKey
>> field that contains a string saying for example "id" and a listValue
>> string
>> saying for example "name" and the select drop would be shown with the
>> list
>> of object's id and it's name value for display.
>>
>> This however no longer works after updating to 2.0.11.2. Substituting ${}
>> with %{} only end it putting the literal value (e.g. "id" and "name") in
>> the
>> drop down box's value and display value. Any idea how I can work around
>> this?
>>
>> Cheers.
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19100876.html
>> Sent from the Struts - User mailing list archive at Nabble.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
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19136189.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.0.11 from 2.0.9 EL Expression problem
Posted by Gabriel Belingueres <be...@gmail.com>.
try using neither ${} nor %{}:
listKey='listKey'
listValue='listValue'
2008/8/22, crappycrumpet <pa...@hotmail.com>:
>
> Hi All,
>
> I know EL Expression has been disabled from 2.0.10 on. Unfortunately I have
> some jsp has uses EL.
> I have this jsp files that renders a generic dropdown box that looks like
> the following.
>
> <s:select name="%{fieldName}"
> list='list'
> listKey='${listKey}'
> listValue='${listValue}'
> multiple='true'
> size='8'
> required="%{required}"
> />
>
> So the action that uses this would have a list of objects and a listKey
> field that contains a string saying for example "id" and a listValue string
> saying for example "name" and the select drop would be shown with the list
> of object's id and it's name value for display.
>
> This however no longer works after updating to 2.0.11.2. Substituting ${}
> with %{} only end it putting the literal value (e.g. "id" and "name") in the
> drop down box's value and display value. Any idea how I can work around
> this?
>
> Cheers.
> --
> View this message in context: http://www.nabble.com/Struts-2.0.11-from-2.0.9-EL-Expression-problem-tp19100876p19100876.html
> Sent from the Struts - User mailing list archive at Nabble.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