You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tal Dayan <ta...@zapta.com> on 2001/07/14 04:35:06 UTC

Standard library

Is there a standard library for Velocity templates for common operations
such as
getting the current date, printing a string to stdout, string
processing, etc ?

Thanks

Tal


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!

Why a singleton pattern?

Posted by Dan Kha <da...@YorkU.CA>.
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: Standard library

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> We just implemented few methods for text formatting, current time and date,
> and
> escaping of HTML code (e.g. change "a > 7" to "a &gt; 7"). Nothing really
> significant.
> 

If you want to contribute them, that would be great.  But of course,
that isn't often possible when developed in a commercial setting, do no
worries if its not possible - just know that contributions are always
welcome.

> How do you see this library from the template user's view point? Will
> it be just a set of independent library objects $mylib.method1(),
> $hislib.method2()
> etc ? What about having a single staring point with some plug in mechanism
> such
> as $lib.mylib1.method1(), $lib.hislib.method2(), etc ?
> 

Well....  We could have some sort of light organization, but I
personally really believe, strongly, that this isn't the business of the
template engine to do this.  Really strongly.  (Our WebMacro bretheren
don't agree, I will note...)

The reason is that this is really the domain of the application, or even
better, the web application framework (like Turbine) that you use to
build your webapp.  

> Having some standard or a framework for the library will make it
> easier to integrate contribution from multiple people.

Yep - in Jakarta there are two, Turbine, which offers excellent support
for Velocity as well as other view technologies, and Struts, which is
more JSP centric although Velocity will work there too.

geir

Y> 
> > -----Original Message-----
> > From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net]On
> > Behalf Of Geir Magnusson Jr.
> > Sent: Friday, July 13, 2001 7:44 PM
> > To: velocity-user@jakarta.apache.org
> > Subject: Re: Standard library
> >
> >
> > Tal Dayan wrote:
> > >
> > > Is there a standard library for Velocity templates for common operations
> > > such as
> > > getting the current date, printing a string to stdout, string
> > > processing, etc ?
> >
> > In velocity, they wouldn't be templates, but 'tools' to put into the
> > context.  We got a few submissions from users and I put them into the
> > Jakarta Commons sandbox, under the mysterious name 'Rupert'.  (I chose
> > rupert because we didn't have a name... :)
> >
> > So thats a start - if you want to use them, grab them.  If you want to
> > start working on the project of organizing and developing more tools,
> > please do.  Take a look and give a shout back here or on the Jakarta
> > commons list.
> >
> > geir
> >
> > --
> > 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!
> >

-- 
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!

RE: Standard library

Posted by Tal Dayan <ta...@zapta.com>.
We just implemented few methods for text formatting, current time and date,
and
escaping of HTML code (e.g. change "a > 7" to "a &gt; 7"). Nothing really
significant.

How do you see this library from the template user's view point? Will
it be just a set of independent library objects $mylib.method1(),
$hislib.method2()
etc ? What about having a single staring point with some plug in mechanism
such
as $lib.mylib1.method1(), $lib.hislib.method2(), etc ?

Having some standard or a framework for the library will make it
easier to integrate contribution from multiple people.

Tal


> -----Original Message-----
> From: gmj@mta4.srv.hcvlny.cv.net [mailto:gmj@mta4.srv.hcvlny.cv.net]On
> Behalf Of Geir Magnusson Jr.
> Sent: Friday, July 13, 2001 7:44 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: Standard library
>
>
> Tal Dayan wrote:
> >
> > Is there a standard library for Velocity templates for common operations
> > such as
> > getting the current date, printing a string to stdout, string
> > processing, etc ?
>
> In velocity, they wouldn't be templates, but 'tools' to put into the
> context.  We got a few submissions from users and I put them into the
> Jakarta Commons sandbox, under the mysterious name 'Rupert'.  (I chose
> rupert because we didn't have a name... :)
>
> So thats a start - if you want to use them, grab them.  If you want to
> start working on the project of organizing and developing more tools,
> please do.  Take a look and give a shout back here or on the Jakarta
> commons list.
>
> geir
>
> --
> 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!
>


Re: Standard library

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> Is there a standard library for Velocity templates for common operations
> such as
> getting the current date, printing a string to stdout, string
> processing, etc ?

In velocity, they wouldn't be templates, but 'tools' to put into the
context.  We got a few submissions from users and I put them into the
Jakarta Commons sandbox, under the mysterious name 'Rupert'.  (I chose
rupert because we didn't have a name... :)

So thats a start - if you want to use them, grab them.  If you want to
start working on the project of organizing and developing more tools,
please do.  Take a look and give a shout back here or on the Jakarta
commons list.

geir

-- 
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!