Well, I did a bunch more homework on this issue and it is getting much harder
than I had expected it to.  The biggest problem is that Spring actually does
the mergeTemplate() itself.  It doesn't leave it for the VVS/VLS.

Here is an example of how Struts would be setup:

----------------------------------------------------------------------------------
<servlet>
 <servlet-name>action</servlet-name>
 <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
 <init-param>
   <param-name>config</param-name>
   <param-value>/WEB-INF/struts-config.xml</param-value>
 </init-param>
</servlet>
<servlet>
 <servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.VelocityLayoutServlet</servlet-class>
 <init-param>
   <param-name>org.apache.velocity.properties</param-name>
   <param-value>/WEB-INF/velocity.properties</param-value>
 </init-param>
 <init-param>
   <param-name>org.apache.velocity.toolbox</param-name>
   <param-value>/WEB-INF/toolbox.xml</param-value>
 </init-param>
</servlet>
<servlet-mapping>
 <servlet-name>action</servlet-name>
 <url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>velocity</servlet-name>
 <url-pattern>*.vm</url-pattern>
</servlet-mapping>
----------------------------------------------------------------------------------

Struts does a request forward to your_page.vm, so the VLS picks up that call. Spring
doesn't work that way at all, so it makes integration harder.



----------------------------------------------------------------------------------
<servlet>
 <servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>myServlet</servlet-name>
 <url-pattern>*.htm</url-pattern>
</servlet-mapping>
----------------------------------------------------------------------------------

No Velocity in there at all. And, Spring doesn't do a request forward to the page
you give as a view.  It finds the templates internally with a ViewResolver:
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/servlet/ViewResolver.html

The ViewResolver (in the form of UrlBasedViewResolver) returns the "viewClass" you specified, the VelocityView. But this is Springs VelocityView, not Velocity's VelocityView.
VelocityView does the following:

----------------------------------------------------------------------------------
protected void mergeTemplate(
Template template, Context context, HttpServletResponse response) throws Exception {
   try {
       template.merge(context, response.getWriter());
   }
   catch (MethodInvocationException ex) {
       throw new NestedServletException(
"Method invocation failed during rendering of Velocity view with name '" + getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
               "], method '" + ex.getMethodName() + "'",
               ex.getWrappedThrowable());
   }
}
----------------------------------------------------------------------------------


Long way of saying that I cannot get a ServletConfig to pass to Velocity's VelocityView. :) The VelocityViewResolver only works with VelocityView. The VelocityToolboxResolver only works with VelocityToolboxView. And the VelocityLayoutViewResolver only works with VelocityLayoutView. Really quite annoying. So I have to make brand new classes, not just extend theirs and replace some methods. And, since I do not have a ServletConfig, I have to pull in the tools.xml file another way. The defaults are great, but I want
to be able to have my tools work as well.

So, what is the best way to get the tools up and running? I know tools 2 is designed
to do just such a thing, but I am not quite up to speed enough to find it.

Thanks again for putting up with such a lengthy dialog.



Charlie



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to