You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jeff Schnitzer <je...@infohazard.org> on 2002/03/06 15:38:31 UTC

[viewservlet] oddities with the ChainedContext

I'm trying to patch the VelocityViewServlet so that the same context is
used for multiple includes/forwards during a single request.  However, I
seem to be thwarted by some unknown and malevolent force :-)

My first thought is to simply save the ChainedContext in the request
attributes and extract for subsequent requests in
VelocityViewServlet.createContext(), like this:

	ChainedContext ctx;
	
	if (persistentContextKey == null)
	{
		ctx = new ChainedContext( null, request, response,
getServletContext() );
	}
	else
	{
		ctx = (ChainedContext)request.getAttribute(
persistentContextKey );
		
		if (ctx == null)
		{
			ctx = new ChainedContext( null, request,
response, getServletContext() );
			request.setAttribute( persistentContextKey, ctx
);
		}
	}

However, this doesn't work, for reasons which apparently require more
understanding of Velocity architecture than I possess.  I can understand
some undesirable behavior here because the request and response objects
might have been substituted at the second invocation, but in my example
that isn't the case.  And without any way of extracting the Map out of
the context, there doesn't seem to be much I can do about it.

Can anyone shed any light on the problem?

Please CC me on any responses, I only read the -dev list out of the
archives, which trail the list by a couple days.

Thanks,
Jeff



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [viewservlet] oddities with the ChainedContext

Posted by Gabriel Sidler <si...@teamup.ch>.
Jeff Schnitzer wrote:
> 
> I'm trying to patch the VelocityViewServlet so that the same context is
> used for multiple includes/forwards during a single request.  However, I
> seem to be hwarted by some unknown and malevolent force :-)
> 
> My first thought is to simply save the ChainedContext in the request
> attributes and extract for subsequent requests in
> VelocityViewServlet.createContext(), like this:
> 
>         ChainedContext ctx;
> 
>         if (persistentContextKey == null)
>         {
>                 ctx = new ChainedContext( null, request, response,
> getServletContext() );
>         }
>         else
>         {
>                 ctx = (ChainedContext)request.getAttribute(
> persistentContextKey );
> 
>                 if (ctx == null)
>                 {
>                         ctx = new ChainedContext( null, request,
> response, getServletContext() );
>                         request.setAttribute( persistentContextKey, ctx
> );
>                 }
>         }
> 

Jeff,
what you do looks perfectly ok to me. 

> However, this doesn't work, for reasons which apparently require more
> understanding of Velocity architecture than I possess.  

How does it not work?

> I can understand
> some undesirable behavior here because the request and response objects
> might have been substituted at the second invocation, but in my example
> that isn't the case.  And without any way of extracting the Map out of
> the context, there doesn't seem to be much I can do about it.

Which Map, which context? Are you saying you can't find the Velocity
context anymore that you stuck into the request attributes? Is is really
the same request?

> 
> Can anyone shed any light on the problem?

How do you pass control between servlets?


Gabe



--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>