velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Petrelli <antonio.petre...@gmail.com>
Subject Re: [tools-2.0] How to access Writer in tool
Date Fri, 27 Feb 2009 13:22:35 GMT
2009/2/27 Antonio Petrelli <antonio.petrelli@gmail.com>:
> 2009/2/26 Nathan Bubna <nbubna@gmail.com>:
>> On Thu, Feb 26, 2009 at 1:41 PM, Antonio Petrelli
>> <antonio.petrelli@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(...)).
>
> Thanks a lot, I will try the Renderable interface.

Tried and it worked :-)
Instead of executing the rendering code directly in the called method,
I create an instance of an anonymous Renderable that is executed when
needed.
Just if you want to take a look:
http://svn.eu.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/InsertDefinitionVModel.java?view=markup

See the "execute" method.

Thanks again!
Antonio

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


Mime
View raw message