struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maxx <maxx...@gmail.com>
Subject Re: Simplified usage of:@com.company.Constants.StaticCOnstants
Date Fri, 06 Jun 2008 10:54:14 GMT
On Thu, May 1, 2008 at 5:21 PM, Jeromy Evans
<jeromy.evans@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


Mime
View raw message