You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Thibaudeau <pi...@gmail.com> on 2008/06/23 09:01:37 UTC

[S2] OGNL and enum

It is possible to refer to an enum value within OGNL:
%{@com.myapp.Planets@MARS}

But how can I refer to the collection of all the values of an enum?  In
Java, that would be:  com.myapp.Planets.values()
With OGNL, I tried the following without success:
%{@com.myapp.Planets@values()}
%{@com.myapp.Planets@values}
%{@com.myapp.Planets.values()}

One option that would work:
%{{@com.myapp.Planets@MERCURY, @com.myapp.Planets@VENUS,
@com.myapp.Planets@EARTH, etc.}}

but that defeats the point, doesn't it?

Re: [S2] OGNL and enum

Posted by Pierre Thibaudeau <pi...@gmail.com>.
> You'll need to enable OGNL's access to static methods.
>
> struts.ognl.allowStaticMethodAccess=true
>

Ah, I didn't know that!


>
> I try  not to use this myself.  Instead I expose a property that provides
> the values so it can sort, lookup I81N text, and minimize dependencies on
> OGNL-specific syntax.
>

Thanks for the advice!

Re: [S2] OGNL and enum

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Pierre Thibaudeau wrote:
> It is possible to refer to an enum value within OGNL:
> %{@com.myapp.Planets@MARS}
>
> But how can I refer to the collection of all the values of an enum?  In
> Java, that would be:  com.myapp.Planets.values()
> With OGNL, I tried the following without success:
> %{@com.myapp.Planets@values()}
> %{@com.myapp.Planets@values}
> %{@com.myapp.Planets.values()}
>   
You'll need to enable OGNL's access to static methods.

struts.ognl.allowStaticMethodAccess=true

Otherwise your approach is fine. 

I try  not to use this myself.  Instead I expose a property that 
provides the values so it can sort, lookup I81N text, and minimize 
dependencies on OGNL-specific syntax.


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