You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Márcio Gurgel <ma...@gmail.com> on 2008/04/07 02:19:51 UTC

Ognl expressions in Struts 2.1

Hi all,

I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
I was setting a value in a checkbox like this:
<s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.

I read this link https://issues.apache.org/struts/browse/WW-2107 and
understood the situation.
But, is there another way to set a value in my checkBox?

<display:table requestURI="/usuario/pesquisar.action" name="listUsuPesquisa"
list="listUsuPesquisa" export="false" class="list" pagesize="15" uid="item">

<display:column title='<input type="checkbox" name="selectAll"
id="selectAll" value="" onclick="checkAll()"/>'>
<s:checkbox name="checkBox" id="checkBox" value="cdUsuario" fieldValue="${
item.id}" theme="simple" onclick="confirmAllChecked()" />
</display>

*Exception*
According to TLD or attribute directive in tag file, attribute fieldValue
does not accept any expressions

Tanks a lot!
Have a nice week!

RE: Ognl expressions in Struts 2.1

Posted by Eric Nelson <er...@unishippers.com>.
I ran into this too once I upgraded to 2.0.11.  I understand their concern for allowing expressions, but I know that I'm using them correctly and so I decided to modify the TLD and allow all expressions, then just re-jared everything up and all is working fine.  That's one solution.  The other is to avoid EL expressions.  The value field in <s:checkbox> can be set off the value stack, so this should work:

<s:checkBox value="currentRow.id"/>

You could also try:

<s:checkBox value="%{currentRow.id}"/>

--Eric

-----Original Message-----
From: Márcio Gurgel [mailto:marcio.rga@gmail.com] 
Sent: Sunday, April 06, 2008 6:20 PM
To: user@struts.apache.org
Subject: Ognl expressions in Struts 2.1

Hi all,

I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
I was setting a value in a checkbox like this:
<s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.

I read this link https://issues.apache.org/struts/browse/WW-2107 and
understood the situation.
But, is there another way to set a value in my checkBox?

<display:table requestURI="/usuario/pesquisar.action" name="listUsuPesquisa"
list="listUsuPesquisa" export="false" class="list" pagesize="15" uid="item">

<display:column title='<input type="checkbox" name="selectAll"
id="selectAll" value="" onclick="checkAll()"/>'>
<s:checkbox name="checkBox" id="checkBox" value="cdUsuario" fieldValue="${
item.id}" theme="simple" onclick="confirmAllChecked()" />
</display>

*Exception*
According to TLD or attribute directive in tag file, attribute fieldValue
does not accept any expressions

Tanks a lot!
Have a nice week!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Ognl expressions in Struts 2.1

Posted by Márcio Gurgel <ma...@gmail.com>.
Sorry guys, my mistake.
I don't know how, but the "theme" attribute of s:checkBox was "item", then I
changed to "simple" (:

Jeromy it works! The generated checkBox has value!
Tanks for your help.
Tanks also Wes!


2008/4/7, Márcio Gurgel <ma...@gmail.com>:
>
> Jeromy,
>
> I tried as you said, but now I have the following exception:
>
> 01:02:36,640  WARN OgnlValueStack:46 - Could not find property
> [templateDir]
> 01:02:36,640  WARN OgnlValueStack:46 - Could not find property
> [templateDir]
> 01:02:36,640  WARN OgnlValueStack:46 - Could not find property
> [#attr.templateDir]
> 01:02:36,656  WARN OgnlValueStack:46 - Could not find property
> [templateDir]
> 01:02:36,656  WARN OgnlValueStack:46 - Could not find property
> [templateDir]
> 01:02:36,671  WARN OgnlValueStack:46 - Could not find property
> [#attr.templateDir]
> 01:02:36,718 ERROR FreemarkerTemplateEngine:24 - Could not load template
> /template/item/checkbox
> 01:02:36,765 ERROR UIBean:28 - error when rendering
> java.io.FileNotFoundException: Template /template/item/checkbox.ftl not
> found.
>
> Tanks for your attention!
>
>
>
> 2008/4/7, Jeromy Evans <je...@blueskyminds.com.au>:
> >
> > In addition to Wes' comment, as you're using display:table and have used
> > the uid attribute, the current row of the table is placed into the
> > PageContext.
> >
> > You can access the page context in OGNL via #attr, so your expression
> > becomes this:
> >
> > <s:checkbox name="checkBox" id="checkBox" value="cdUsuario"
> > fieldValue="%{#attr.item.id}" theme="simple"
> > onclick="confirmAllChecked()" />
> >
> >
> > Wes Wannemacher wrote:
> >
> > > Your problem isn't OGNL in parameters, you are using EL in your
> > > examples. By default, EL expressions are disabled, but you could
> > > easily
> > > switch your expressions to OGNL. I'm guessing that if you use '%'
> > > instead of '$' it will probably work. If your action has a getItem(),
> > > and the returned object has a getId(), then %{item.id} should work,
> > > and
> > > if the %{ and } may not even be necessary.
> > > ${ triggers EL expression parsing, but this is done by the app server,
> > > if the TLD specifies that the attribute accepts EL (which struts tags
> > > do
> > > not by default, unless you change the TLD which isn't advisable).
> > > %{ forces OGNL expression. OGNL expression evaluation happens within
> > > the
> > > tag's code, so the app server knows nothing about this step. Thus, the
> > > TLD file's directives have nothing to do with this parsing. Many of
> > > the
> > > Struts 2 tag's attributes will attempt to parse parameters as OGNL by
> > > default, but %{ will force parsing.
> > >
> > > -Wes
> > >
> > >
> > > On Sun, 2008-04-06 at 21:19 -0300, Márcio Gurgel wrote:
> > >
> > >
> > > > Hi all,
> > > >
> > > > I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
> > > > I was setting a value in a checkbox like this:
> > > > <s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.
> > > >
> > > > I read this link https://issues.apache.org/struts/browse/WW-2107 and
> > > > understood the situation.
> > > > But, is there another way to set a value in my checkBox?
> > > >
> > > > <display:table requestURI="/usuario/pesquisar.action"
> > > > name="listUsuPesquisa"
> > > > list="listUsuPesquisa" export="false" class="list" pagesize="15"
> > > > uid="item">
> > > >
> > > > <display:column title='<input type="checkbox" name="selectAll"
> > > > id="selectAll" value="" onclick="checkAll()"/>'>
> > > > <s:checkbox name="checkBox" id="checkBox" value="cdUsuario"
> > > > fieldValue="${
> > > > item.id}" theme="simple" onclick="confirmAllChecked()" />
> > > > </display>
> > > >
> > > > *Exception*
> > > > According to TLD or attribute directive in tag file, attribute
> > > > fieldValue
> > > > does not accept any expressions
> > > >
> > > > Tanks a lot!
> > > > Have a nice week!
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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: Ognl expressions in Struts 2.1

Posted by Márcio Gurgel <ma...@gmail.com>.
Jeromy,

I tried as you said, but now I have the following exception:

01:02:36,640  WARN OgnlValueStack:46 - Could not find property [templateDir]
01:02:36,640  WARN OgnlValueStack:46 - Could not find property [templateDir]
01:02:36,640  WARN OgnlValueStack:46 - Could not find property
[#attr.templateDir]
01:02:36,656  WARN OgnlValueStack:46 - Could not find property [templateDir]
01:02:36,656  WARN OgnlValueStack:46 - Could not find property [templateDir]
01:02:36,671  WARN OgnlValueStack:46 - Could not find property
[#attr.templateDir]
01:02:36,718 ERROR FreemarkerTemplateEngine:24 - Could not load template
/template/item/checkbox
01:02:36,765 ERROR UIBean:28 - error when rendering
java.io.FileNotFoundException: Template /template/item/checkbox.ftl not
found.

Tanks for your attention!



2008/4/7, Jeromy Evans <je...@blueskyminds.com.au>:
>
> In addition to Wes' comment, as you're using display:table and have used
> the uid attribute, the current row of the table is placed into the
> PageContext.
>
> You can access the page context in OGNL via #attr, so your expression
> becomes this:
>
> <s:checkbox name="checkBox" id="checkBox" value="cdUsuario"
> fieldValue="%{#attr.item.id}" theme="simple" onclick="confirmAllChecked()"
> />
>
>
> Wes Wannemacher wrote:
>
> > Your problem isn't OGNL in parameters, you are using EL in your
> > examples. By default, EL expressions are disabled, but you could easily
> > switch your expressions to OGNL. I'm guessing that if you use '%'
> > instead of '$' it will probably work. If your action has a getItem(),
> > and the returned object has a getId(), then %{item.id} should work, and
> > if the %{ and } may not even be necessary.
> > ${ triggers EL expression parsing, but this is done by the app server,
> > if the TLD specifies that the attribute accepts EL (which struts tags do
> > not by default, unless you change the TLD which isn't advisable).
> > %{ forces OGNL expression. OGNL expression evaluation happens within the
> > tag's code, so the app server knows nothing about this step. Thus, the
> > TLD file's directives have nothing to do with this parsing. Many of the
> > Struts 2 tag's attributes will attempt to parse parameters as OGNL by
> > default, but %{ will force parsing.
> >
> > -Wes
> >
> >
> > On Sun, 2008-04-06 at 21:19 -0300, Márcio Gurgel wrote:
> >
> >
> > > Hi all,
> > >
> > > I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
> > > I was setting a value in a checkbox like this:
> > > <s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.
> > >
> > > I read this link https://issues.apache.org/struts/browse/WW-2107 and
> > > understood the situation.
> > > But, is there another way to set a value in my checkBox?
> > >
> > > <display:table requestURI="/usuario/pesquisar.action"
> > > name="listUsuPesquisa"
> > > list="listUsuPesquisa" export="false" class="list" pagesize="15"
> > > uid="item">
> > >
> > > <display:column title='<input type="checkbox" name="selectAll"
> > > id="selectAll" value="" onclick="checkAll()"/>'>
> > > <s:checkbox name="checkBox" id="checkBox" value="cdUsuario"
> > > fieldValue="${
> > > item.id}" theme="simple" onclick="confirmAllChecked()" />
> > > </display>
> > >
> > > *Exception*
> > > According to TLD or attribute directive in tag file, attribute
> > > fieldValue
> > > does not accept any expressions
> > >
> > > Tanks a lot!
> > > Have a nice week!
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > 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: Ognl expressions in Struts 2.1

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
In addition to Wes' comment, as you're using display:table and have used 
the uid attribute, the current row of the table is placed into the 
PageContext.

You can access the page context in OGNL via #attr, so your expression 
becomes this:

<s:checkbox name="checkBox" id="checkBox" value="cdUsuario" fieldValue="%{#attr.item.id}" theme="simple" onclick="confirmAllChecked()" />


Wes Wannemacher wrote:
> Your problem isn't OGNL in parameters, you are using EL in your
> examples. By default, EL expressions are disabled, but you could easily
> switch your expressions to OGNL. I'm guessing that if you use '%'
> instead of '$' it will probably work. If your action has a getItem(),
> and the returned object has a getId(), then %{item.id} should work, and
> if the %{ and } may not even be necessary. 
>
> ${ triggers EL expression parsing, but this is done by the app server,
> if the TLD specifies that the attribute accepts EL (which struts tags do
> not by default, unless you change the TLD which isn't advisable). 
>
> %{ forces OGNL expression. OGNL expression evaluation happens within the
> tag's code, so the app server knows nothing about this step. Thus, the
> TLD file's directives have nothing to do with this parsing. Many of the
> Struts 2 tag's attributes will attempt to parse parameters as OGNL by
> default, but %{ will force parsing.
>
> -Wes
>
>
> On Sun, 2008-04-06 at 21:19 -0300, Márcio Gurgel wrote:
>   
>> Hi all,
>>
>> I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
>> I was setting a value in a checkbox like this:
>> <s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.
>>
>> I read this link https://issues.apache.org/struts/browse/WW-2107 and
>> understood the situation.
>> But, is there another way to set a value in my checkBox?
>>
>> <display:table requestURI="/usuario/pesquisar.action" name="listUsuPesquisa"
>> list="listUsuPesquisa" export="false" class="list" pagesize="15" uid="item">
>>
>> <display:column title='<input type="checkbox" name="selectAll"
>> id="selectAll" value="" onclick="checkAll()"/>'>
>> <s:checkbox name="checkBox" id="checkBox" value="cdUsuario" fieldValue="${
>> item.id}" theme="simple" onclick="confirmAllChecked()" />
>> </display>
>>
>> *Exception*
>> According to TLD or attribute directive in tag file, attribute fieldValue
>> does not accept any expressions
>>
>> Tanks a lot!
>> Have a nice week!
>>     
>
>
> ---------------------------------------------------------------------
> 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: Ognl expressions in Struts 2.1

Posted by Márcio Gurgel <ma...@gmail.com>.
Hi all!

Wes, tanks for your explanation, it was helpful.
I tryed to use %{  -  %{item.id}       inside my display:table, but it still
doesn't work.
The iterated object is a bean, the attribute "cd" has a getCd()

Folow the generated html:

<input name="checkBox" value="" id="checkBox"
onclick="confirmaAllChecked()" type="checkbox">



2008/4/6, Wes Wannemacher <we...@wantii.com>:
>
> Your problem isn't OGNL in parameters, you are using EL in your
> examples. By default, EL expressions are disabled, but you could easily
> switch your expressions to OGNL. I'm guessing that if you use '%'
> instead of '$' it will probably work. If your action has a getItem(),
> and the returned object has a getId(), then %{item.id} should work, and
> if the %{ and } may not even be necessary.
>
> ${ triggers EL expression parsing, but this is done by the app server,
> if the TLD specifies that the attribute accepts EL (which struts tags do
> not by default, unless you change the TLD which isn't advisable).
>
> %{ forces OGNL expression. OGNL expression evaluation happens within the
> tag's code, so the app server knows nothing about this step. Thus, the
> TLD file's directives have nothing to do with this parsing. Many of the
> Struts 2 tag's attributes will attempt to parse parameters as OGNL by
> default, but %{ will force parsing.
>
> -Wes
>
>
>
> On Sun, 2008-04-06 at 21:19 -0300, Márcio Gurgel wrote:
> > Hi all,
> >
> > I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
> > I was setting a value in a checkbox like this:
> > <s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.
> >
> > I read this link https://issues.apache.org/struts/browse/WW-2107 and
> > understood the situation.
> > But, is there another way to set a value in my checkBox?
> >
> > <display:table requestURI="/usuario/pesquisar.action"
> name="listUsuPesquisa"
> > list="listUsuPesquisa" export="false" class="list" pagesize="15"
> uid="item">
> >
> > <display:column title='<input type="checkbox" name="selectAll"
> > id="selectAll" value="" onclick="checkAll()"/>'>
> > <s:checkbox name="checkBox" id="checkBox" value="cdUsuario"
> fieldValue="${
> > item.id}" theme="simple" onclick="confirmAllChecked()" />
> > </display>
> >
> > *Exception*
> > According to TLD or attribute directive in tag file, attribute
> fieldValue
> > does not accept any expressions
> >
> > Tanks a lot!
> > Have a nice week!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Ognl expressions in Struts 2.1

Posted by Wes Wannemacher <we...@wantii.com>.
Your problem isn't OGNL in parameters, you are using EL in your
examples. By default, EL expressions are disabled, but you could easily
switch your expressions to OGNL. I'm guessing that if you use '%'
instead of '$' it will probably work. If your action has a getItem(),
and the returned object has a getId(), then %{item.id} should work, and
if the %{ and } may not even be necessary. 

${ triggers EL expression parsing, but this is done by the app server,
if the TLD specifies that the attribute accepts EL (which struts tags do
not by default, unless you change the TLD which isn't advisable). 

%{ forces OGNL expression. OGNL expression evaluation happens within the
tag's code, so the app server knows nothing about this step. Thus, the
TLD file's directives have nothing to do with this parsing. Many of the
Struts 2 tag's attributes will attempt to parse parameters as OGNL by
default, but %{ will force parsing.

-Wes


On Sun, 2008-04-06 at 21:19 -0300, Márcio Gurgel wrote:
> Hi all,
> 
> I was using struts 2.0.9, then I resolved to upgrade to 2.1.0.
> I was setting a value in a checkbox like this:
> <s:checkBox value="${currentRow.id}"/> inside a displayTag iterator.
> 
> I read this link https://issues.apache.org/struts/browse/WW-2107 and
> understood the situation.
> But, is there another way to set a value in my checkBox?
> 
> <display:table requestURI="/usuario/pesquisar.action" name="listUsuPesquisa"
> list="listUsuPesquisa" export="false" class="list" pagesize="15" uid="item">
> 
> <display:column title='<input type="checkbox" name="selectAll"
> id="selectAll" value="" onclick="checkAll()"/>'>
> <s:checkbox name="checkBox" id="checkBox" value="cdUsuario" fieldValue="${
> item.id}" theme="simple" onclick="confirmAllChecked()" />
> </display>
> 
> *Exception*
> According to TLD or attribute directive in tag file, attribute fieldValue
> does not accept any expressions
> 
> Tanks a lot!
> Have a nice week!


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org