You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dan Kha <da...@YorkU.CA> on 2001/07/14 05:12:51 UTC

Why a singleton pattern?

Hi,

I'm just curious, why does velocity use a singleton design pattern (pros,
cons)?

Are there plans to change it?  I guess I find it weird to include the
velocity.jar in every webapp's lib directory.

Thanks,
dan


Re: Incorrectly formatted templates

Posted by Kelvin Tan <ke...@relevanz.com>.
Sorry I omitted the fact that I'm using Velocity 1.01.

----- Original Message -----
From: "Kelvin Tan" <ke...@relevanz.com>
To: <ve...@jakarta.apache.org>
Sent: Saturday, July 14, 2001 4:58 PM
Subject: Incorrectly formatted templates


> I've found it somewhat odd that if I don't format my Velocity templates
> correctly in the case of servlets (omitting a #end or using #if(dfdf)
> instead of #if($dfdf)), the error returned is
>
> VelocityServlet : Error processing the template
> java.lang.Exception: handleRequest(Context) returned null - no template
> selected!
> java.lang.Exception: handleRequest(Context) returned null - no template
> selected! at
>
org.apache.velocity.servlet.VelocityServlet.handleRequest(VelocityServlet.ja
> va:561) at
>
org.apache.velocity.servlet.VelocityServlet.doRequest(VelocityServlet.java:3
> 33) at
>
org.apache.velocity.servlet.VelocityServlet.doGet(VelocityServlet.java:294)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at
> org.apache.tomcat.core.Handler.service(Handler.java:287) at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at
>
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
> 7) at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
> at
>
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
> onnectionHandler.java:213) at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
> at java.lang.Thread.run(Thread.java:484)
>
> Now, is this supposed to be the way it is, or am I not setting something
up
> correctly.
>
> If this is the way it is, I must say the error message is not exactly very
> helpful, since it was more a problem with my template, rather than that
"no
> template (had been) selected".
>
> Thanks.
>
>


Re: Incorrectly formatted templates

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Yes... in Velocity 1.1, there are two handleRequest() methods.  The
better one to use is
handleRequest( HttpServletRequest, HttpServletResponse, Context)...


The thing to make sure you do in handleRequest() is catch the Exceptions
from getTemplate() - that is where the parsing would be done, so you
would then know if you had a syntax problem, and could then take steps
to deal with it.

Take a look a the Javadoc to see what getTemplate() will throw.

geir


Kelvin Tan wrote:
> 
> I've found it somewhat odd that if I don't format my Velocity templates
> correctly in the case of servlets (omitting a #end or using #if(dfdf)
> instead of #if($dfdf)), the error returned is
> 
> VelocityServlet : Error processing the template
> java.lang.Exception: handleRequest(Context) returned null - no template
> selected!
> java.lang.Exception: handleRequest(Context) returned null - no template
> selected! at
> org.apache.velocity.servlet.VelocityServlet.handleRequest(VelocityServlet.ja
> va:561) at
> org.apache.velocity.servlet.VelocityServlet.doRequest(VelocityServlet.java:3
> 33) at
> org.apache.velocity.servlet.VelocityServlet.doGet(VelocityServlet.java:294)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405) at
> org.apache.tomcat.core.Handler.service(Handler.java:287) at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
> 7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
> at
> org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
> onnectionHandler.java:213) at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416) at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
> at java.lang.Thread.run(Thread.java:484)
> 
> Now, is this supposed to be the way it is, or am I not setting something up
> correctly.
> 
> If this is the way it is, I must say the error message is not exactly very
> helpful, since it was more a problem with my template, rather than that "no
> template (had been) selected".
> 
> Thanks.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Incorrectly formatted templates

Posted by Kelvin Tan <ke...@relevanz.com>.
I've found it somewhat odd that if I don't format my Velocity templates
correctly in the case of servlets (omitting a #end or using #if(dfdf)
instead of #if($dfdf)), the error returned is

VelocityServlet : Error processing the template
java.lang.Exception: handleRequest(Context) returned null - no template
selected!
java.lang.Exception: handleRequest(Context) returned null - no template
selected! at
org.apache.velocity.servlet.VelocityServlet.handleRequest(VelocityServlet.ja
va:561) at
org.apache.velocity.servlet.VelocityServlet.doRequest(VelocityServlet.java:3
33) at
org.apache.velocity.servlet.VelocityServlet.doGet(VelocityServlet.java:294)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405) at
org.apache.tomcat.core.Handler.service(Handler.java:287) at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:213) at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416) at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)

Now, is this supposed to be the way it is, or am I not setting something up
correctly.

If this is the way it is, I must say the error message is not exactly very
helpful, since it was more a problem with my template, rather than that "no
template (had been) selected".

Thanks.


Re: Why a singleton pattern?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Dan Kha wrote:
> 
> Hi,
> 
> I'm just curious, why does velocity use a singleton design pattern (pros,
> cons)?

That was the way it started.  It works very well, as services for the
subcomponents are immediately available.  The cons are obvious :)

> 
> Are there plans to change it?  I guess I find it weird to include the
> velocity.jar in every webapp's lib directory.

I am working on that as we speak. Really.  This is my current mission...
I hope to have something soon.

I actually prefer putting a vel jar in every WEB-INF/lib.  I don't have
any shared jars if I can help it, because then I know that my webapp is
portable anywhere - it doesn't depend upon the explicit classpath, or
the implicit one you get when you drop a jar in the containers /lib.

Also, it means I can experiment / upgrade jars a will in individual
webapps w/o fear of interferance between them.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!