You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Maxx <ma...@gmail.com> on 2008/06/06 12:54:14 UTC
Re: Simplified usage of:@com.company.Constants.StaticCOnstants
On Thu, May 1, 2008 at 5:21 PM, Jeromy Evans
<je...@blueskyminds.com.au> wrote:
>
> I have a solution, but first...
> OGNL only provides access to static fields and static methods. It cannot
> reference a static class, nor even an inner static class.
>
> http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/apa.html
Strange... because I succeeded in reading Enum values from an inner
enum class, like:
public interface MyInterface {
enum MyEnum {
MY_ENUM_VALUE;
}
}
Using
<s:property value="@com.mycompany.some.package.MyInterface$MyEnum@MY_ENUM_VALUE"
/>
prints:
MY_ENUM_VALUE
(value returned by the .toString() from the Enum class)
Note: it might be dumb to do this, BUT if you use a specific Struts2
(or XWork?) converter to "translate" your enum value into something
different (e.g. introducing a label or something similar that would
returns "My Enum Value" in our example) then it's useful when not only
dealing with the Enum name (i.e. here MY_ENUM_VALUE).
I also succeeded using
<s:property value="@java.lang.Math@PI" />
that prints:
2.718281828459045
But strangely, some:
<s:property value="@com.mycompany.some.package.MyInterface@MY_CONSTANT_VALUE"
/>
does not work... why?!
... all this with Struts 2.0.11.1
> However, there is a bearable solution / hack:
>
> 1. In your Constants *class*, create a public static singleton instance of
> itself. Lets call it C. (Remember, OGNL can reference static fields)
> public static final Constants C = new Constants();
>
> 2. [...]
And what if, as from my above explained example, you have an
*interface*, not a class...?
Maxx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org