velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <>
Subject Re: changes template path after init
Date Mon, 03 Jan 2005 17:47:44 GMT
On Mon, 3 Jan 2005 14:38:51 +0100, Geercken Uwe
<> wrote:
> hello everybody and a happy new year,
> my web app based on the VelocityLayoutServlet works fine so far. the
> startup/default template path is "., de/template", my layout dir path
> is: "de/layout/" and this all comes from the file.
> but now I want to change the template path after the initialisation, to
> be able to allow a user of the app to select a different language. my
> controller servlet extends VelocityLayoutServlet. in the handleRequest()
> method I added following code:
> public Template handleRequest(HttpServletRequest
> request,HttpServletResponse response,
> org.apache.velocity.context.Context context ) throws Exception
> {
> Vector v = new Vector();
> v.add(".");
> v.add("eng/template");
> ExtendedProperties ep = this.loadConfiguration(this.getServletConfig());
> ep.setProperty("webapp.resource.loader.path",v);
> ep.setProperty("","eng/layout");
> this.init();
> ...
> ...
> return template;
> }
> but this does not work. it always uses the default settings from the
> file. can please somebody give me a hint of what I
> am doing wrong?

well, you can't change a VelocityEngine's (or the Velocity singletons)
properties once they've been set.  so the way you're going about it is

changing the layout directory of the VLS (VelocityLayoutServlet) is
easy though.  the VLS keeps a layoutDir field that is just a protected
String.  so in your subclass, you only need to do

this.layoutDir = "eng/layout";

and that should do the trick.

changing the template path is trickier since that is passed to the
WebappLoader during initialization (that's what the whole
webapp.resource.loader.path thing is, of course).  i think what you'll
have to do is create your own resource loader that allows you to
update the search paths.  i'm not sure offhand the best way to do this
though.  my initial thought would be to extend the WebappLoader and
give it some faculty to either receive path updates or else check for
them itself (the former would probably be more efficient).  the
RuntimeServices.set/getApplicationAttribute(...) will probably be your
best friends for doing this. (for an example of how this is used, look
at the VelocityViewServlet's initVelocity() method and WebappLoader's
init() method.

hope this helps.

> thanks.
> uwe geercken
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message