Jeff Schnitzer wrote:

> The result is that nothing appears to be found in the context.  Neither
> values that were set from a previous template with #set($title = "foo")
> nor values that exist in the request attribute collection are found.
> The output just has the literals $title and $wrapped in it.


There is an important distinction to be made here:
1) Objects defined in the Velocity context with #set($title = "foo") are
*not* passed from template to template when you use forward() or include().
2) Objects defined as request attributes ($request.setAttribute($key, $value))
*are* passed from template to template when you use forward() or include().

[it's debatable if this is the desired behavior but that's how it's
implemented at the moment]

Can you verify that case 2) works in your example. If this doesn't work,
please verify that you have the same request object everywhere. For example,
do a $request.toString() in each template and compare the output.


> According to my debugging code, I *am* successfully obtaining the same
> ChainedContext from the request collection.  It just doesn't seem to
> contain any of the stuff I expect it to.


What do you mean you "obtain the same ChainedContext from the request
collection". I don't see why the ChainedContext every would be stored
in  the request collection. Maybe I just don't quite understand yet
how your setup is.


> 
> What I'm doing is executing the first velocity template with
> RequestDispatcher.include() to the VelocityViewServlet (using a
> HttpServletResponseWrapper that simply buffers the output), then
> executing the second velocity template using
> RequestDispatcher.forward().  The buffered output of the first template
> is stored in the request attribute collection as a String with the key
> "wrapped".  This is all within the same http request.


If the output of the first template is stored as a request attribute
then it *should* be availble in the second template. If this is not
the case, then my only guess is that you have not the same request object.

If the problem persists, send some code examples.


Gabe


> 
> So this *should* work?
> 
> Thanks,
> Jeff Schnitzer
> [EMAIL PROTECTED]
> 
> 
>>-----Original Message-----
>>From: Gabriel Sidler [mailto:[EMAIL PROTECTED]]
>>Sent: Thursday, March 07, 2002 7:31 AM
>>To: Velocity Developers List
>>Cc: Jeff Schnitzer
>>Subject: Re: [viewservlet] oddities with the ChainedContext
>>
>>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:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 


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


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

Reply via email to