Struts 2
  1. Struts 2
  2. WW-3296

Full integration with SiteMesh 2 + Freemarker 2.4.2 + Velocity 1.3 , including struts tags, value stack, and FreemarkerManager statics.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: 2.2.1
    • Component/s: Plugin - SiteMesh
    • Labels:
      None
    • Flags:
      Patch, Important

      Description

      Current issues include:

      • limiting decorators to use 1 technology (Freemarker, Velocity, or JSP) only. SiteMesh should be able to use any of the three decorators as definied in decorators.xml
      • velocity struts tags and toolchain not available to velocity decorators, .
      • freemarker statics and manager configuration not available to freemarker decorators.
      • in general, the decorators use a completely different manager.
      • problems mixing freemarker decorators with velocity/jsp results and vice versa.

      This improvement/patch will use the SiteMeshFilter provided by SiteMesh and implement a Freemarker and Velocity dispatcher that uses the appropriate Managers in Struts 2 to create their contexts and configurations, as well as share the same model when available. If the context has not been created for that technology, the Struts Manager will be asked to construct one. Since many of these configurations were constructed multiple times, there should be a small speed improvement as well. Once implemented, there will not be a restriction on decorators.xml on which technology is being used, and the same context will be available to the decorators as is available to the results.

      The new web.xml will look like this (configuration to use all three technologies).

      <filter>
      <filter-name>struts-prepare</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
      <init-param>
      <param-name>actionPackages</param-name>
      <param-value>net.stonescape.renegade20.presentation</param-value>
      </init-param>
      </filter>

      <filter>
      <filter-name>sitemesh</filter-name>
      <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
      </filter>

      <filter>
      <filter-name>struts-execute</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
      </filter>

      <filter-mapping>
      <filter-name>struts-prepare</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
      <filter-name>sitemesh</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>INCLUDE</dispatcher>
      </filter-mapping>
      <filter-mapping>
      <filter-name>struts-execute</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>

      <servlet>
      <servlet-name>sitemesh-freemarker</servlet-name>
      <servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class>
      <init-param>
      <param-name>default_encoding</param-name>
      <param-value>UTF-8</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
      <servlet-name>sitemesh-freemarker</servlet-name>
      <url-pattern>*.ftl</url-pattern>
      </servlet-mapping>

      <servlet>
      <servlet-name>sitemesh-velocity</servlet-name>
      <servlet-class>org.apache.struts2.sitemesh.VelocityDecoratorServlet</servlet-class>
      <init-param>
      <param-name>default_encoding</param-name>
      <param-value>UTF-8</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
      <servlet-name>sitemesh-velocity</servlet-name>
      <url-pattern>*.vm</url-pattern>
      </servlet-mapping>

      <servlet>
      <servlet-name>JspSupportServlet</servlet-name>
      <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
      </servlet>

        Issue Links

          Activity

          Hide
          Christian Wolfgang Stone added a comment -

          Note that I have already implemented this and will have a patch available in the next several days...

          Show
          Christian Wolfgang Stone added a comment - Note that I have already implemented this and will have a patch available in the next several days...
          Hide
          Christian Wolfgang Stone added a comment -

          This resolves WW-2865 as well.

          Show
          Christian Wolfgang Stone added a comment - This resolves WW-2865 as well.
          Hide
          Christian Wolfgang Stone added a comment -

          The following files have been modified. Updating doc comments and should have a patch ready next week early.

          M plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsDecorator.java
          M plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreeMarkerPageFilter.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsFreemarkerDecorator.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityMapper2DecoratorSelector.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
          D plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java
          A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreeMarkerMapper2DecoratorSelector.java
          M plugins/sitemesh/src/main/resources/struts-plugin.xml
          M core/src/main/java/org/apache/struts2/views/freemarker/ScopesHashModel.java
          M core/src/main/java/org/apache/struts2/views/freemarker/StrutsBeanWrapper.java
          M core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
          M core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java

          Show
          Christian Wolfgang Stone added a comment - The following files have been modified. Updating doc comments and should have a patch ready next week early. M plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsDecorator.java M plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreeMarkerPageFilter.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsFreemarkerDecorator.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityMapper2DecoratorSelector.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java D plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java A plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreeMarkerMapper2DecoratorSelector.java M plugins/sitemesh/src/main/resources/struts-plugin.xml M core/src/main/java/org/apache/struts2/views/freemarker/ScopesHashModel.java M core/src/main/java/org/apache/struts2/views/freemarker/StrutsBeanWrapper.java M core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java M core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
          Hide
          Lukasz Lenart added a comment -

          Any news on that? It would be nice to include your changes in incoming 2.2.0 release!

          Show
          Lukasz Lenart added a comment - Any news on that? It would be nice to include your changes in incoming 2.2.0 release!
          Hide
          Christian Wolfgang Stone added a comment -

          This should be fixed with the October patch I submitted to Musachy to test and check in. The code seems to all be in place!

          Musachy, can you make one more change to help with logging...

          Index: FreemarkerDecoratorServlet.java
          ===================================================================
          — FreemarkerDecoratorServlet.java (revision 923504)
          +++ FreemarkerDecoratorServlet.java (working copy)
          @@ -195,7 +195,7 @@

          StringBuilder msgBuf = new StringBuilder("Error applying freemarker template to\n request: ");
          msgBuf.append(req.getRequestURL());

          • if (req.getQueryString() == null) msgBuf.append("?").append(req.getQueryString());
            + if (req.getQueryString() != null) msgBuf.append("?").append(req.getQueryString());
            msgBuf.append(" with resultCode: ").append(resultCode).append(".\n\n").append(x.getMessage());
            String msg = msgBuf.toString();
            LOG.error(msg, x);

          There is a logic error that I made when adding the logging comment. It is very very useful (well at least for me), as I know the full request URL for an error.

          Show
          Christian Wolfgang Stone added a comment - This should be fixed with the October patch I submitted to Musachy to test and check in. The code seems to all be in place! Musachy, can you make one more change to help with logging... Index: FreemarkerDecoratorServlet.java =================================================================== — FreemarkerDecoratorServlet.java (revision 923504) +++ FreemarkerDecoratorServlet.java (working copy) @@ -195,7 +195,7 @@ StringBuilder msgBuf = new StringBuilder("Error applying freemarker template to\n request: "); msgBuf.append(req.getRequestURL()); if (req.getQueryString() == null) msgBuf.append("?").append(req.getQueryString()); + if (req.getQueryString() != null) msgBuf.append("?").append(req.getQueryString()); msgBuf.append(" with resultCode: ").append(resultCode).append(".\n\n").append(x.getMessage()); String msg = msgBuf.toString(); LOG.error(msg, x); There is a logic error that I made when adding the logging comment. It is very very useful (well at least for me), as I know the full request URL for an error.
          Hide
          Christian Wolfgang Stone added a comment -

          Please note, the web.xml needs to be modified. The old filters are still supported, so to take advantage of the new functionality, you should do the following:

          <filter>
          <filter-name>struts-prepare</filter-name>
          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
          <init-param>
          <param-name>actionPackages</param-name>
          <param-value>net.stonescape</param-value>
          </init-param>
          </filter>

          <filter>
          <filter-name>sitemesh</filter-name>
          <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
          </filter>

          <filter>
          <filter-name>struts-execute</filter-name>
          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
          </filter>

          <filter-mapping>
          <filter-name>struts-prepare</filter-name>
          <url-pattern>/*</url-pattern>
          </filter-mapping>
          <filter-mapping>
          <filter-name>sitemesh</filter-name>
          <url-pattern>/*</url-pattern>
          <dispatcher>REQUEST</dispatcher>
          <dispatcher>FORWARD</dispatcher>
          <dispatcher>INCLUDE</dispatcher>
          </filter-mapping>
          <filter-mapping>
          <filter-name>struts-execute</filter-name>
          <url-pattern>/*</url-pattern>
          </filter-mapping>

          <servlet>
          <servlet-name>sitemesh-freemarker</servlet-name>
          <servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class>
          <init-param>
          <param-name>default_encoding</param-name>
          <param-value>UTF-8</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
          </servlet>
          <servlet-mapping>
          <servlet-name>sitemesh-freemarker</servlet-name>
          <url-pattern>*.ftl</url-pattern>
          </servlet-mapping>

          <servlet>
          <servlet-name>JspSupportServlet</servlet-name>
          <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
          </servlet>

          <listener>
          <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
          </listener>

          Best of luck. I have been testing this for months, and it is a real benison!

          Show
          Christian Wolfgang Stone added a comment - Please note, the web.xml needs to be modified. The old filters are still supported, so to take advantage of the new functionality, you should do the following: <filter> <filter-name>struts-prepare</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>net.stonescape</param-value> </init-param> </filter> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter> <filter-name>struts-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <filter-mapping> <filter-name>struts-execute</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>sitemesh-freemarker</servlet-name> <servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class> <init-param> <param-name>default_encoding</param-name> <param-value>UTF-8</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sitemesh-freemarker</servlet-name> <url-pattern>*.ftl</url-pattern> </servlet-mapping> <servlet> <servlet-name>JspSupportServlet</servlet-name> <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <listener> <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class> </listener> Best of luck. I have been testing this for months, and it is a real benison!
          Hide
          Lukasz Lenart added a comment -

          I added you web.xml configuration to docs -> http://cwiki.apache.org/confluence/display/WW/SiteMesh+Plugin

          Show
          Lukasz Lenart added a comment - I added you web.xml configuration to docs -> http://cwiki.apache.org/confluence/display/WW/SiteMesh+Plugin

            People

            • Assignee:
              Christian Wolfgang Stone
              Reporter:
              Christian Wolfgang Stone
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development