Hi Shinobu, Thanks for the reply. I'd like to understand this a little deeper.
> > So my question is, how do I get ahold of the actual stream that the > > velocity engine is using, from within a template, and add my own > > output to it? Is this possible, or is there a better way? > > You can't. Also, Velocity outputs to Writers, not Streams. Writers are fine, I don't actually need the stream. > I'm not sure what exactly you're trying to do, but some suggestions: > - Put a String representation of the Stream in the Context and render it. > - Create a $RefenceToAnObjectWithAStream.streamToString() method and call it. > - Create a tool that converts a Stream to a String and call it. > - Put a StringWriter wrapped in an OutputStreamWriter in the Context and > render it after calling your > $RefenceToAnObjectWithAStream.streamToOutput() method. Here's what I'm doing: I've written a reusable html-control model for creating html components within the struts framework using velocity. These components use velocity themselves to render their content. These controls may also themselves contain other sub-controls, and so on. It seems ineffecient for me for each of these sub-controls, to have to create a single large string and return it to its parent control to render it. I would rather pass a writer down through the execution hierarchy having each subcontrol add its output to the parents writer, thus using a single writer to achieve the total output, instead of a segmented writer.toString -> writer.toString -> writer.toString sort of process. Does that make more sense? Evan Leonard -----Original Message----- From: Shinobu Kawai [mailto:[EMAIL PROTECTED] Sent: Monday, March 28, 2005 12:19 PM To: Velocity Users List Subject: Re: Streaming from the middle of a template? Hi Evan, > My name is Evan Leonard. This is my first post to the users group, so > I'd like to start by saying, great work with velocity. I am enjoying > working with it very much. Simple & powerful, excellent. Welcome to the gang! :) > I am mainly using velocity in a struts/servlet situation, but I'd like > a more general answer that would work in other environments as well. > My question has to do with writing directly to the output stream that the > velocity engine is using, mid-template. For instance if I have a template > that looks like: > > ...[some html]... > > $RefenceToAnObjectWithAStream.streamToOutput($ReferenceToOutputStream) > > ...[some more html]... > > I'm not sure what output stream to pass to the streaming function. > I've tried using $response.getOutputStream and $response.getWriter > from within the template. I've tried making a velocity view tool that > grabs the response in its init method and holds on to it until the > tool is used. But these methods all create very unusual results, like > outputing things in the wrong order, or not outputing some things at all. > > So my question is, how do I get ahold of the actual stream that the > velocity engine is using, from within a template, and add my own > output to it? Is this possible, or is there a better way? You can't. Also, Velocity outputs to Writers, not Streams. I'm not sure what exactly you're trying to do, but some suggestions: - Put a String representation of the Stream in the Context and render it. - Create a $RefenceToAnObjectWithAStream.streamToString() method and call it. - Create a tool that converts a Stream to a String and call it. - Put a StringWriter wrapped in an OutputStreamWriter in the Context and render it after calling your $RefenceToAnObjectWithAStream.streamToOutput() method. Best regards, -- Shinobu -- Shinobu Kawai <[EMAIL PROTECTED]> --------------------------------------------------------------------- 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]