One possibility-- consider writing your own resource loader, using the
FileResourceLoader as a model.  If this resource loader caches based
on filesystem location you should be able to maintain Velocity's
performance.

Instead of configuring the resource loader class via properties, use
dependency injection.  (required version 1.5).  Using Spring to
instantiate your resource loader configured with your dynamic path
info.  Then pass the live resource loader into Velocity when
initializing.  See:
http://jroller.com/page/raible?anchor=loading_velocity_templates_from_the


WILL

On 1/23/07, darrowj <[EMAIL PROTECTED]> wrote:

Thanks Nathan.

I did post this question on the Spring Forum first but got no response.
Since I cannot seem to do exactly what I want I am using what you are
calling a pathfinder.  The thing that sucks is that I need to change the
returns from all my controllers and than the includes inside all my
templates.

No stress here though.  I have a work around.  It just seems like bad form
and in the long run will potentially be harder to maintain.

Again, thanks for the response.

Jason


Nathan Bubna wrote:
>
> I haven't used Spring with Velocity, so i can't help much.  You may
> have more luck on the spring forums.  That said, here's a few thoughts
> that may or may not help.
>
> On 1/22/07, darrowj <[EMAIL PROTECTED]> wrote:
>>
>> I have a client that wants to be able to display a totally different set
>> of
>> Velocity
>> templates based on the Domain a user enters a web app. So completely
>> different presentation layer but the same controllers, services, and
>> database.
>>
>> I've created an Interceptor that finds the domain and the domainDirectory
>> where the velocity templates will live for said domain and puts it in
>> session for a given user.
>>
>> I could do something like return 'new ModelAndView(domainDirectory +
>> "/home");'
>> but I would rather not have to edit all of my controllers if possible
>> because I think things will quickly change.
>
> Quickly changing things are difficult, but Spring's DI should help.
> You could always create a "pathfinder" type object that your
> controllers would use to find the right path, then inject the
> pathfinder into your controllers, and just change the pathfinder
> whenever "things change".
>
>> I'd like to dynamically change the Velocity resourceLoaderPath somehow
>> based
>> on the domain a user uses to get to the web application.
>
> That may be both difficult and unwise if Spring directly feeds that
> path to the resourceLoader that Velocity's runtime is using.  Changing
> it might mean re-initializing Velocity every time you want to change
> the path.  That would cause very poor performance.
>
>> I've done a lot of searching and read that the VelocityEngineFactoryBean
>> may
>> be what I need but cannot make it work. In my appname-servlet.xml I have
>> the
>> following:
>>
>> <bean id="velocityConfigurer"
>> class="org.springframework.web.servlet.view.veloci
>> ty.VelocityConfigurer">
>> <property name="resourceLoaderPath">
>> <value>WEB-INF/velocity</value>
>> </property>
>> </bean>
>>
>> <bean id="velocityEngine"
>> class="org.springframework.ui.velocity.VelocityEng
>> ineFactoryBean">
>> <property name="velocityProperties">
>> <props>
>> <prop key="resource.loader">class</prop>
>> <prop key="class.resource.loader.class">org.apache.veloc
>> ity.runtime.resource.loader.ClasspathResourceLoade r</prop>
>> </props>
>> </property>
>> </bean>
>>
>> <bean id="domainInterceptor"
>> class="com.somedomain.web.DomainInterceptor">
>> <property name="communityContextService">
>> <ref bean="communityContextService"/>
>> </property>
>> <property name="velocityEngine">
>> <ref bean="velocityEngine"/>
>> </property>
>> </bean>
>>
>> This does not work as my Interceptor complains of an setter error and
>> I've
>> reviewed and cannot resolve the problem.
>>
>> My real question is can the Velocity resourceLoaderPath be set
>> dynamically
>> by your web application? If so am I on the right track?
>> --
>> View this message in context:
>> 
http://www.nabble.com/Dynamic-Velocity-resourceLoaderPath-in-Spring--tf3061673.html#a8513803
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>

--
View this message in context: 
http://www.nabble.com/Dynamic-Velocity-resourceLoaderPath-in-Spring--tf3061673.html#a8553396
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Forio Business Simulations

Will Glass-Husain
[EMAIL PROTECTED]
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to