Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking static methods on inner classes via value stack

 
Andy Wilson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2 doesn't seem to allow methods on inner classes to be called via the value stack.
Say I have the following class structure:

package com.spam;

public class Outerclass {

public String outerMethod() {
return "outer";
}

public class InnerClass {
public String innerMethod() {
return "inner";
}
}
}


The if I have a jsp containing the following two tags:

<s:text name="@com.spam.Outerclass@outerMethod()" />
<s:text name="@com.spam.Outerclass.InnerClass@innerMethod()" />

The first tag will call the outerMethod and render the result "outer".
However, the second tag doesn't call the innerMethod and instead renders the
string "@com.spam.Outerclass.InnerClass@innerMethod()".

Does anyone know if it should be possible to do this and if so how?

BTW: I'm using struts 2.1.8.

Cheers,
AW
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

Personally, I didn't even know that syntax would work on non-static methods--I'm a little surprised. Aside from that, I'm not sure. You might have better luck asking on the Struts user mailing list; I'm not overly-familiar with how OGNL's static method syntax works under the covers.
 
Robert Nelson
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure this is too old for you to care anymore, Andy, but I just spent the better part of my day figuring this out and it must be posted *somewhere*!

Apparently, in OGNL, the @ symbol is for accessing stuff statically, and the $ is for accessing inner classes. In my case, I wanted to access an enum in one of my classes, which I did by doing:



In your case, I'm guessing this would work...



Again, I spent far too long looking for a solution. Apparently OGNL is partially undocumented. Bah!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic