[prev in list] [next in list] [prev in thread] [next in thread]
List: velocity-user
Subject: Re: Velocity into a plug-in
From: jian chen <chenjian1227 () gmail ! com>
Date: 2012-05-26 17:59:20
Message-ID: CAC78mAOi5s6yfJ7c8y9dfrGKcbF2k_C2yL29C07wiG0Zaie+NQ () mail ! gmail ! com
[Download RAW message or body]
Hi Vanessa,
It looks to me that you are relying on the default way that Velocity
loads its templates. I am not sure if it is loading from classpath?
But, typically I would use more explicit way to load templates, for
example, just use the file system path like this:
File templateDir = new File("/path/to/template");
ve = new VelocityEngine();
// setting up file resource loader
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
templateDir.getCanonicalPath());
This way, you have total control and know where to load the templates.
As for the output, it is as simple as:
OutputStreamWriter out = new
OutputStreamWriter(response.getOutputStream(), "UTF-8");
ve.mergeTemplate(viewName + ".html", "UTF-8", ctx, out);
if (flushOutput)
{
out.flush();
}
This is pretty much how I am using Velocity right now. Hope it helps.
Jian
http://www.JiansNet.com
Useful Info on Living In USA, Powered By Velocity
On Sat, May 26, 2012 at 9:13 AM, vanessa vanessa
<vanessa032012@gmail.com> wrote:
> Hi all ,
>
> I'm using velocity in a plug-in projet.In the root of my plugin
> i put a folder templates/template.vm. And i call the template
> velocity.getTemplate(template.vm) from my class.
> But the resource is not found i don't no why its directory isn't
> recognised.the template cannot be loaded.
>
> Every thing work fine in a java-Project.
> I will appreciate any help.
> Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic