On Thu, Feb 26, 2009 at 1:41 PM, Antonio Petrelli
<antonio.petre...@gmail.com> wrote:
> Hi all
> Is there a way to access the writer that is used to write in the
> response, from a request-scoped tool?

In Velocity 1.6, we introduced the
org.apache.velocity.runtime.Renderable interface, which has a "boolean
execute(context, writer)" method.  If, when rendering a reference,
Velocity comes across a Renderable, it calls that method instead of
calling toString() and writing that value.  but even if you do
implement Renderable, please consider having your toString() be
functional (e.g. passing a StringWriter and null context to
execute(...)).

> I tried using the HttpServletResponse's writer, but it writes included
> resources in wrong order (as I suspected). It is the same effect that
> you would have in JSP tags when you use HttpServletResponse's writer
> instead of PageContext's one.

yeah, we want content to run through Velocity, direct writing is frowned upon.

> I took a look at TilesTool and I noticed that, in fact, the included
> resources are transformed in strings and then returned to the
> template. Sincerely I don't like it.

it keeps things orderly and flexible, allowing, for instance, tools to
grab each other out of the context and interact with the same API.
but yes, it can be a performance hit in situations involving a lot of
content.

> In TilesViewServlet I noticed that, if "bufferOutput" is true, a
> StringWriter is used, otherwise the HttpServletResponse's one is used.
> I wish to use the correct writer in both cases.

please do!  but your options are restricted to Renderable (Velocity
1.6+) or toString() (any version).  Velocity is not in the business of
handing out the writer to objects before it is time to render them,
sorry.  Users can hack that in easily by extending VelocityView and
overwriting performMerge(..) to drop the writer in the context, but
that won't work well for a TilesTool.

> Thanks in advance
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
> For additional commands, e-mail: user-h...@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org

Reply via email to