velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <>
Subject Re: Simple design
Date Tue, 01 Jun 2004 12:21:25 GMT

On May 25, 2004, at 7:41 PM, Barbara Baughman wrote:

> Example of a simple but useful design, for what it's worth.
> I have a MAIN controller that extends HttpServlet and gets the
> function name to call from the request parameter "function". The value
> for the function parameter is provided in the request URL or from a
> hidden parameter (INPUT TYPE="hidden" NAME="function").


I have a really hokey little approach that is similar.  I have a base 
class in which the service() method looks for 'action' parameter (like 
your 'function')

It then simply invokes a public method <action>(HttpServletRequest, 
HttpServletResponse, VelocityContext)

it's really embarrassing because it's so simple, but I get tremendous 
mileage out of it.  The base class gets vel setup and has some helper 
methods.  It then makes my servlets look like :

public class Foo extends VelocityActionServlet
     public String getTemplateRoot()
         return "foo/";

     public void defaultAction(HttpServletRequest req,
             HttpServletResponse res,
             VelocityContext ctx)
         throws javax.servlet.ServletException, IOException

         ctx.put("entityCount", new Integer(Util.getEntityCount()));
         ctx.put("body_template", "index.vm");
         renderTemplate(req, res, ctx, "frame.vm");

The context that's handed to me is created by the baseclass, and I can 
override the creation routine to fill w/ tools, for example, or ignore 
that context.

it's simple and lightweight, but I never have complicated things to 
build with it....

Geir Magnusson Jr                                   203-247-1713(m)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message