You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Ramapuram <th...@gmail.com> on 2008/03/14 07:29:21 UTC

Question regarding OGNL

Hi, 
I have query regarding OGNL Expression.   
Can the "#name" kind of expression be used anywhere? Or are they 
applicable only in certain attributes of struts tags 

Till now I was using the %{name} expression and that too in the some 
attribute of a tag 

I tried using #name expression but it does not work.  Is there any 
settings to be set (for example in web.xml) 
Any pointers would be a great help. 
Thanks 
Thomas


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


Re: [struts] Re: Question regarding OGNL

Posted by Dale Newfield <Da...@Newfield.org>.
Laurie Harper wrote:
> The expressions %{name} and %{#name} have different meanings. Anywhere 
> one is valid, the other is valid too but obviously each will only 'work' 
> if the expression resolves to a value.

Correct.  I'm sorry to pick nits, but if you don't mind, I'll clarify 
your following statements in the hopes that this becomes clearer to more 
people:

>  - %{name} will look for a property named 'name' on your action (i.e. 
> will result in a call to getName() on your action)

%{name} will look for "name" on the Value Stack.  Typically while 
executing in .jsp's the top item in that stack is your Action, but 
within an iterator, for example, there might be something "on top of" 
the Action, and there are always other objects below the Action.

OGNL will start at the top of the stack and search each object for a 
getName() getter, returning the results of the first such getter found.

>  - %{#name} will look for a property or attribute named 'name' anywhere 
> in the value stack, including in the request/session/application scopes

%{#name} will not look in the value stack at all.  It will look for a an 
object named "name" stored in a separate Map<String,Object> separately 
from the VS (Stack<Object>).  Some struts tags push/pop items on to the 
top of the VS, some just store in this hash.  (Possibly some do both 
when asked to, in which case it's the same object both in the VS and 
directly referencible through that Map.)

> AFAIK, %{#name} is equivalent to %{name} when there is a getName() on 
> the action, i.e. OGNL will look at the action first then search the rest 
> of the value stack.

AFAIK that is incorrect.

Special items in that Map:

#application
#session
#request
#parameters

I believe at least some of those are also in the VS.

#attr searches the normal (EL) scopes in normal (EL) order (application, 
session, request, and page)  (Note, #page is not in the Map.)

-Dale

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


Re: [struts] Question regarding OGNL

Posted by Dale Newfield <Da...@Newfield.org>.
Martin Gainty wrote:
> dave is is correct..

The following example without the proceeding situation setup is quite 
misleading (so here it is) :

For example, suppose we are using standard OGNL (not using XWork) and 
there are two objects in the OgnlContext map: "foo" -> foo and "bar" -> 
bar and that the foo object is also configured to be the single root 
object. The following code illustrates how OGNL deals with these three 
situations:

> #foo.blah // returns foo.getBlah()
> #bar.blah // returns bar.getBlah()
> blah      // returns foo.getBlah() because foo is the root

So the third line is only true because in this scenario foo is BOTH #foo 
AND the VS root.

> http://struts.apache.org/2.x/docs/ognl-basics.html

-Dale


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


Re: Question regarding OGNL

Posted by Martin Gainty <mg...@hotmail.com>.
dave is is correct..

#foo.blah // returns foo.getBlah()
#bar.blah // returns bar.getBlah()
blah      // returns foo.getBlah() because foo is the root

http://struts.apache.org/2.x/docs/ognl-basics.html

Martin-
----- Original Message -----
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, March 14, 2008 2:19 PM
Subject: Re: Question regarding OGNL


> --- Laurie Harper <la...@holoweb.net> wrote:
> > AFAIK, %{#name} is equivalent to %{name} when there is a getName() on
> > the action, i.e. OGNL will look at the action first then search the rest
> > of the value stack.
>
> Mmm, I'm not sure about that. The "#" should look explicitly for a named
> object in the stack context rather than calling getXxx() on stack objects.
>
> For example, if I have:
>
>       <p>Prop from Sanity action: <s:property value="sanityCheck"/></p>
>       <p>Prop from Sanity action: <s:property value="#sanityCheck"/></p>
>
> only the first one will print the action's getSanityCheck() value.
>
> Not that I just happened to have that example laying around or anything
geeky
> like that.
>
> *ahem*
>
> Chup Chups!
>
> 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: Question regarding OGNL

Posted by Dave Newton <ne...@yahoo.com>.
--- Laurie Harper <la...@holoweb.net> wrote:
> AFAIK, %{#name} is equivalent to %{name} when there is a getName() on 
> the action, i.e. OGNL will look at the action first then search the rest 
> of the value stack.

Mmm, I'm not sure about that. The "#" should look explicitly for a named
object in the stack context rather than calling getXxx() on stack objects.

For example, if I have:

      <p>Prop from Sanity action: <s:property value="sanityCheck"/></p>
      <p>Prop from Sanity action: <s:property value="#sanityCheck"/></p>

only the first one will print the action's getSanityCheck() value.

Not that I just happened to have that example laying around or anything geeky
like that.

*ahem*

Chup Chups!

Dave


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


Re: Question regarding OGNL

Posted by Laurie Harper <la...@holoweb.net>.
Thomas Ramapuram wrote:
> Hi, 
> I have query regarding OGNL Expression.   
> Can the "#name" kind of expression be used anywhere? Or are they 
> applicable only in certain attributes of struts tags 
> 
> Till now I was using the %{name} expression and that too in the some 
> attribute of a tag 
> 
> I tried using #name expression but it does not work.  Is there any 
> settings to be set (for example in web.xml) 
> Any pointers would be a great help. 
> Thanks 
> Thomas

The expressions %{name} and %{#name} have different meanings. Anywhere 
one is valid, the other is valid too but obviously each will only 'work' 
if the expression resolves to a value.

  - %{name} will look for a property named 'name' on your action (i.e. 
will result in a call to getName() on your action)

  - %{#name} will look for a property or attribute named 'name' anywhere 
in the value stack, including in the request/session/application scopes

AFAIK, %{#name} is equivalent to %{name} when there is a getName() on 
the action, i.e. OGNL will look at the action first then search the rest 
of the value stack.

L.


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


Re: Question regarding OGNL

Posted by Rushikesh Thakkar <th...@gmail.com>.
AFAIK you can use OGNL expression in any attribute of your struts2 tag.
Your problem could be 'what is the proper syntax for using OGNL
expression?'.
Can you post your relevant code? I might get an idea of what you are trying
to achieve.

-Rushikesh

On Fri, Mar 14, 2008 at 7:29 AM, Thomas Ramapuram <
thomas.ramapuram@gmail.com> wrote:

> Hi,
> I have query regarding OGNL Expression.
> Can the "#name" kind of expression be used anywhere? Or are they
> applicable only in certain attributes of struts tags
>
> Till now I was using the %{name} expression and that too in the some
> attribute of a tag
>
> I tried using #name expression but it does not work.  Is there any
> settings to be set (for example in web.xml)
> Any pointers would be a great help.
> Thanks
> Thomas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>