Getting access to the Struts2 OGNL stack in a JSP

Sometimes, you need to directly use the OGNL stack in a JSP, for instance when you have the "nested tags" problem and one tag needs access to a value that's only available through a Struts tag.

Here's one solution:

      <%
        // This is equivalent to <s:property name="id"/>
        com.opensymphony.xwork2.util.ValueStack stack = 
            (com.opensymphony.xwork2.util.ValueStack) request.getAttribute("struts.valueStack");
        String id = (String) stack.findValue("id", String.class);
      %>

Struts2OGNLJSP (last edited 2008-07-09 06:21:44 by localhost)