You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Gagnon <mg...@genome.med.harvard.edu> on 2008/03/20 16:09:02 UTC

OGNL Method calls & class static properties

Is it valid to, within the scope if a s:if tag, to:

a)       Call non getter/setter methods on a bean on the stack

b)       Reference some unrelated class' public static field (without a
getter method)

 

To give the situation some context, I'm attempting to do something similar
to the following:

            <s:iterator value="someSet" status="stat" id="next">

                        <s:property value="name"/>

                        .etc.

                        <s:if test="hasRoleType(user,
database.roles.RoleTypeEnum.ADMIN)">

                                    Add some link

                        </s:if>

            </s:iterator>

 

Where the calling action has a method getSomeSet which returns a set of
objects containing a hasRoleType method. The hasRoleType method takes two
parameters and returns a boolean. 

 

The calling action also has a method getUser which returns a 'User' object.

 

database.roles.RoleTypeEnum is just a class on the classpath - not
referenced in any way by the action - which has a 'public static RoleType
ADMIN' field. This field has no getters or setters.

 

What I *expect* to magically happen in a perfect world is that:

            OGNL looks for hasRoleType method on the next iterating object -
this should have highest priority on the stack. Being found (and having a
return type of boolean) this method should be set to be called

 

            OGNL looks for 'getUser' method on the next iterating object.
Not being found, it checks the action for a getUser method. It finds it and
uses it.

 

            OGNL looks for 'getDatabase' on the iterating object. Doesn't
find it. Checks on the action. Doesn't find it. Then maybe it shrugs its
shoulders and decides it's a qualified java class with a field? I guess
that's a stretch.

 

Is there some syntax for calling a method on that next object on the stack,
and is there also some syntax for making a static reference like that
(Without taking the trouble of putting a getXX method in the action to just
return it)?

 

Any thoughts/insights would be appreciated, thanks!


Re: OGNL Method calls & class static properties

Posted by Dave Newton <ne...@yahoo.com>.
Static access:
http://struts.apache.org/2.x/docs/ognl-basics.html

--- Michael Gagnon <mg...@genome.med.harvard.edu> wrote:

> Is it valid to, within the scope if a s:if tag, to:
> 
> a)       Call non getter/setter methods on a bean on the stack
> 
> b)       Reference some unrelated class' public static field (without a
> getter method)
> 
>  
> 
> To give the situation some context, I'm attempting to do something similar
> to the following:
> 
>             <s:iterator value="someSet" status="stat" id="next">
> 
>                         <s:property value="name"/>
> 
>                         .etc.
> 
>                         <s:if test="hasRoleType(user,
> database.roles.RoleTypeEnum.ADMIN)">
> 
>                                     Add some link
> 
>                         </s:if>
> 
>             </s:iterator>
> 
>  
> 
> Where the calling action has a method getSomeSet which returns a set of
> objects containing a hasRoleType method. The hasRoleType method takes two
> parameters and returns a boolean. 
> 
>  
> 
> The calling action also has a method getUser which returns a 'User' object.
> 
>  
> 
> database.roles.RoleTypeEnum is just a class on the classpath - not
> referenced in any way by the action - which has a 'public static RoleType
> ADMIN' field. This field has no getters or setters.
> 
>  
> 
> What I *expect* to magically happen in a perfect world is that:
> 
>             OGNL looks for hasRoleType method on the next iterating object
> -
> this should have highest priority on the stack. Being found (and having a
> return type of boolean) this method should be set to be called
> 
>  
> 
>             OGNL looks for 'getUser' method on the next iterating object.
> Not being found, it checks the action for a getUser method. It finds it and
> uses it.
> 
>  
> 
>             OGNL looks for 'getDatabase' on the iterating object. Doesn't
> find it. Checks on the action. Doesn't find it. Then maybe it shrugs its
> shoulders and decides it's a qualified java class with a field? I guess
> that's a stretch.
> 
>  
> 
> Is there some syntax for calling a method on that next object on the stack,
> and is there also some syntax for making a static reference like that
> (Without taking the trouble of putting a getXX method in the action to just
> return it)?
> 
>  
> 
> Any thoughts/insights would be appreciated, thanks!
> 
> 


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