You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Geir Magnusson Jr <ge...@4quarters.com> on 2004/06/01 14:21:25 UTC

Re: Simple design

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").
>

[SNIP]

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)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org