I have a working Struts 2 application where I am using Velocity AND Freemarker decorators now intechangeably and SiteMesh is dispatching them. The full value stacks are available in each, as the same Configurations are running on both the decorators and the struts results. You can now have decorators in Freemarker, Velocity, and JSP as long as the servlets are defined in your web.xml. I had to make a lot of changes to bring the plugin up to date with the modern freemarker, so good that this will be getting in early! Note that the old plugin fix I did is still there, so you can use either of the two published solutions you wish, and you no longer are using a crippled Freemarker with the new solution (shown below).

I think my chin dropped when I saw all the decorators mixed in one decorator.xml and compiling. I am accessing all my statics in my freemarker decorator (velocity 1.3 does not support such things), so that is fixed as well. Absolutely sweet! On another note, I was able to streamline the process a bit, so there should be a subtle speed improvement as well.

Here is an example web.xml snippet with the new changes hilighted. Currently I read the configuration from freemarker.properties as well as velocity.properties, and add any parameters present in the servlet, so the init phase for the two technologies is a bit more flexible and dynamic.

    <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>
         <filter-name>timing</filter-name>
<filter-class>net.stonescape.common.filter.TimerFilter</ filter-class>
     </filter>


     <filter-mapping>
         <filter-name>timing</filter-name>
         <url-pattern>/*</url-pattern>
         <dispatcher>REQUEST</dispatcher>
     </filter-mapping>
     <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>

  -- Christian Stone

On Oct 22, 2009, at 4:00 PM, Musachy Barroso wrote:

that sounds pretty reasonable to me. if you are up for the task, go
for it. 2.2 is far in the horizon and this would be a good time for
this kind of stuff.

musachy

--
           _,--"
cws        `-._        ________-_______         "----
       _----'--'--------------------------------'--'----_
      //_| | \ Christian Stone, Software Engineer / | |_\\
     (_____|_|__=     xt...@stonescape.net     =__|_|_____)
     _\_____=__   http://xtian.stonescape.net/        ___/_
       \/-(o)-~~-(o)-~~-(o)-`------'-(o)-~~-(o)-~~-(o)-\/



Reply via email to