You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Olivier <ol...@zip.com.au> on 2000/09/28 04:09:50 UTC

Example.java

Dear Velocity,

I am rather new to Velocity (yesterday) so I hope not wasting
anybody's time. 

I use myself a little template engine I wrote a couple of months ago.
This is not very powerful but was enought for my needs.

it can only do two things:

  - replace a variable by its value
  - or trigger a call to a sub container and resolve the variable
    according to the output of this sub container (using its own templates).

That was OK so far but I definitivelly need something more powerful, so
thanks for the hard work! Velocity is looking great!

However I am running into some troubles with the Examples.
I retrieved the CVS tree yesterday (and did an update this morning).

The install went all right but I cannot get the example to work!



I fixed some obvious mistake in examples/Example.java but still can't
get it to work.

This is what I did so far:


file: examples/Example.java


replaced:

import org.apache.velocity.Configuration;
import org.apache.velocity.runtime.TemplateFactory;
import org.apache.velocity.runtime.TemplateLoader;

by

import org.apache.velocity.runtime.configuration.Configuration;
import org.apache.velocity.runtime.loader.TemplateFactory;
import org.apache.velocity.runtime.loader.TemplateLoader;



replaced:

TemplateLoader loader = TemplateFactory.getLoader();

by

TemplateLoader loader = TemplateFactory.getLoader("org.apache.velocity.runtime.FileTemplateLoader");




and finally:

Configuration.getString (Configuration.TEMPLATE_ENCODING)
Configuration.getBoolean (Configuration.TEMPLATE_ASCIIHACK)

by

"UTF8"
false




After that point I could compile the Example.java file however I still get
the following runtime error:


tournesol:~/jakarta/jakarta-velocity/examples$ java Example example.vm 
java.lang.NullPointerException
java.lang.NullPointerException
	at org.apache.velocity.runtime.Runtime.error(Runtime.java:175)
	at
org.apache.velocity.runtime.loader.TemplateFactory.getLoader(TemplateFactory.java:88)
	at Example.<init>(Example.java:83)
	at Example.main(Example.java:119)




Obviously you guys have been reorganising the class hierarchy but
might not have time to update the example directory.

Could anyone, please, update the examples? That would greatly help me
to get started with Velocity.


Thanks a lot.

Olivier

-- 
----------------------------------------------------------------------
Olivier Louchart-Fletcher
Email: olivier@zipworld.com.au

Re: Example.java

Posted by Jason van Zyl <jv...@periapt.com>.
On Thu, 28 Sep 2000, Olivier wrote:

> Thanks Jason,
> 
> that got me on track!
> 
> I have a test Servlet runing now!! Hehe!
> 
> However, unlike the rg/apache/velocity/servlet/VelocityServlet.java, 
> I had to add a 'flush' at the end of my Servlet to get a response back. 
> 
> i.e.:
> 
>         response.setContentType("text/html");
>         
>         writer = new FastWriter(response.getOutputStream(), encoding);
>         writer.setAsciiHack(asciiHack);
>         template.merge( context, writer );
> 
> 	writer.flush();   // **added that line**

Great, I'll add that line to make things happy!

Much appreciated!

jvz.

-- 

Jason van Zyl
jvanzyl@periapt.com


Re: Example.java

Posted by Olivier <ol...@zip.com.au>.
On Wed, Sep 27, 2000 at 10:25:50PM -0400, Jason van Zyl wrote:

> Before you go to far, the examples directory is constantly
> out of date because Velocity's been changing everyday. In the testbed
> directory are example templates that I always test with. If
> you want to see a working example you can play with
> 
> org.apache.velocity.test.Test
> 
> This is the class that I use and it works. The files in the
> example directory probably don't work as there is no
> official release, and it is changing on a daily basis
> right now. My apologies. There is also a little shell
> script in the testbed directory
> 
> ./test.sh your_template.vm
> 

Thanks Jason,

that got me on track!

I have a test Servlet runing now!! Hehe!

However, unlike the rg/apache/velocity/servlet/VelocityServlet.java, 
I had to add a 'flush' at the end of my Servlet to get a response back. 

i.e.:

        response.setContentType("text/html");
        
        writer = new FastWriter(response.getOutputStream(), encoding);
        writer.setAsciiHack(asciiHack);
        template.merge( context, writer );

	writer.flush();   // **added that line**


Otherwise I would get a zero-size response. I have not tested with Tomcat, this is the behavior I get with Orion web server.

 
Thanks.

Olivier

-- 
----------------------------------------------------------------------
Olivier Louchart-Fletcher
Email: olivier@zipworld.com.au

Re: Example.java

Posted by Jason van Zyl <jv...@periapt.com>.
On Thu, 28 Sep 2000, Olivier wrote:

> Dear Velocity,
> 
> I am rather new to Velocity (yesterday) so I hope not wasting
> anybody's time. 
> 
> I use myself a little template engine I wrote a couple of months ago.
> This is not very powerful but was enought for my needs.
> 
> it can only do two things:
> 
>   - replace a variable by its value
>   - or trigger a call to a sub container and resolve the variable
>     according to the output of this sub container (using its own templates).
> 
> That was OK so far but I definitivelly need something more powerful, so
> thanks for the hard work! Velocity is looking great!
> 
> However I am running into some troubles with the Examples.
> I retrieved the CVS tree yesterday (and did an update this morning).
> 
> The install went all right but I cannot get the example to work!

Before you go to far, the examples directory is constantly
out of date because Velocity's been changing everyday. In the testbed
directory are example templates that I always test with. If
you want to see a working example you can play with

org.apache.velocity.test.Test

This is the class that I use and it works. The files in the
example directory probably don't work as there is no
official release, and it is changing on a daily basis
right now. My apologies. There is also a little shell
script in the testbed directory

./test.sh your_template.vm

> Obviously you guys have been reorganising the class hierarchy but
> might not have time to update the example directory.
> 
> Could anyone, please, update the examples? That would greatly help me
> to get started with Velocity.

Just use the org.apache.velocity.test.Test file as a basis
for anything your doing. It uses the Runtime and the interface
to the Runtime won't be changing much anymore, if at all.

Again, my apologies, I'll fix the examples directory and
update it to reflect the use of the Runtime.

Thanks Olivier,

jvz.

-- 

Jason van Zyl
jvanzyl@periapt.com