http://servlets.com/archive/servlet/ReadMsg?msgId=511851&listName=velocity-user
Summarize by: | Date | Author | Subject | Thread | Search |
Description: velocity-user@jakarta.apache.org (See other lists) Subject: changes template path after init |
|
Nathan Bubna (nbubna@gmail.com) writes on 2005-01-03 (display as raw message) |
Date: Mon, 3 Jan 2005 09:47:44 -0800 From: Nathan Bubna <nbubna@gmail.com> Subject: Re: changes template path after init Content-Type: text/plain; charset=US-ASCII |
On Mon, 3 Jan 2005 14:38:51 +0100, Geercken Uwe <Uwe.Geercken@swissport.com> 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 velocity.properties 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("tools.view.servlet.layout.directory","eng/layout"); > this.init(); > ... > ... > return template; > } > > but this does not work. it always uses the default settings from the > velocity.properties 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 wrong. 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: velocity-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: velocity-user-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: velocity-user-help@jakarta.apache.org |