I think you've put your finger on the crux of my issue.  I don't really,
fully, understand how VelocityViewServlet determines which template to
display.  At least, I didn't until a little while ago.

I've opted to recode my application to load templates from a directory
structure that looks a lot like an old-time HTML document tree.  Each
servlet will have all of its templates stored in an directory with the same
name as the tail of the servlet's URL.  In each directory, the servlet's
default template is placed in the file index.vm (taking the place of the
traditional index.html).

I've over-ridden the getTemplate() method in VelocityViewServlet as follows:

Public Template getTemplate(String name) 
  throws ResourceNotFoundException, ParseErrorException, Exception {
    if (name.endsWith("/") || ! Name.endsWith(".vm")) {
      name = name + "/index.vm";
    }

    return super.getTemplate(name);
}

This seems to do what I expect.

I did not note in my earlier message that I'm 'somewhat' constrained in the
URL format for each servlet in the application as backward compatibility to
earlier versions of the application is required.

Thanks to everyone for all their help.

John

John Withers


-----Original Message-----
From: Nathan Bubna [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 27, 2005 12:16 PM
To: Velocity Users List
Subject: Re: More help with VelocityViewServlet needed


it's not clear to me from your code snippets just how the servlet is
supposed to know which template to load and merge.  how are you
telling the servlet what resource to load?  did you override the
handleRequest(...) and/or getTemplate(...) methods?  if so, what are
they doing?

On 7/27/05, Withers John Z <[EMAIL PROTECTED]> wrote:
>  
> Hello all. 
>   
> I know I've asked for help before and I know I've already asked this
> question before.  I would, normally, search through the message archive,
but
> my employer has seen fit to configure our firewall to 'block' that site...
> IMHO, its because the word 'mail' appears in the host name and we're not
> supposed to visit any site that allows us to post 'webmail'. 
>   
> I'm converting an existing web application that uses Velocity to use the
> VelocityViewServlet.  In the original application, I created a base class
> that performed many of the the velocity-specific housekeeping functions
that
> the various servlet in the application required.  While this works well
> enough, it doesn't support the concept of a toolbox and I think a toolbox
> would be handy.  Instead of reinventing the wheel (yet again), I'm trying
to
> use VelocityViewServlet to replace the base class that I developed. 
>   
> This is what my velocity.properties file looks like: 
>   
> webapp.resource.loader.path = /WEB-INF/templates 
> velocimacro.library = Macros3.0.vm 
>   
> This is what part of my web.xml file looks like.  I've trimmed out most of
> the servlet definitions to save space: 
>   
> <web-app> 
>   <context-param> 
>    <param-name>org.apache.velocity.properties</param-name> 
>    <param-value>/WEB-INF/velocity.properties</param-value> 
>   </context-param> 
>   
>   <!-- BrowseServlet extends VelocityViewServlet to manage a cookie and to
> place results in the context 
>         based on the query part of the client's URL --> 
>   
>   <servlet> 
>    <servlet-name>browse</servlet-name> 
>    <servlet-class>BrowseServlet</servlet-class> 
>   </servlet> 
>   
>   <servlet-mapping> 
>    <servlet-name>browse</servlet-name> 
>    <url-pattern>/browse</url-pattern> 
>   </servlet-mapping> 
> </web-app> 
>   
> When the client attempts to access the URL
> http://host.com/application/browse?name=x, a message with a
> stack trace is displayed in the browser indicating that '/browse' couldn't
> be found in any resource loader.  A single index.vm doesn't seem to be
> appropriate as there are several several servlet components in the
> 'application' web-app.  What am I missing?  None of the examples provided
> with the Velocity tools seems to address this situation. 
>   
> Thanks!
>  
> John 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
>

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

Reply via email to