You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Shinobu Kawai Yoshida <sh...@gmail.com> on 2005/01/23 15:40:17 UTC

Re: Many calls to init(Object o) in tool extending ViewTool in request scop

Hi Matt,

> I have a simple print line in the init function of my tool. On every
> page I hit .. including pages that don't use the tool (This makes some
> sense to me), the init function is called 22 times. This seams strange
> and wrong to me? This leads me to believe that every tool in the request
> scope will have similar behavior??? This is quite a bit of over head.
> 
> I am using Velocity with Struts / Tiles if that makes a difference.

That's exactly your problem.  Tiles uses the include feature of the
Servlet API to render the tiles.  This causes a servlet invocation on
each tile, as you suspected.

BTW, you say it's an overhead, but how much of an overhead is it?  Do
you have some heavy duty initialization process in your tool?  I
usually don't care about performance until it becomes an issue,
because that (to shun performance) leads to simpler design.

> Is there any way to stop this? Am I using the tool box inappropriately?
> Any suggestions would be helpful. My suspicion is each tile is somehow
> generating a new request? If this is true is there a way to avoid this?

You can try out VelocityLayoutServlet.  This controls the output only
by Velocity, thus only initializing the ViewTool only once.
   http://jakarta.apache.org/velocity/tools/view/index.html#VelocityLayoutServlet

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

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