struts-user mailing list archives

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

Strange... because I succeeded in reading Enum values from an inner
enum class, like:

public interface MyInterface {
  enum MyEnum {

  <s:property value="@com.mycompany.some.package.MyInterface$MyEnum@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:

But strangely, some:
  <s:property value="@com.mycompany.some.package.MyInterface@MY_CONSTANT_VALUE"
does not work... why?!

... all this with Struts

> 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...?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message