changes template path after init[velocity]

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
Browse list Browse messages with this subject Browse this thread Browse messages by this author
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
| | |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值