velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jason.Br...@cox.com>
Subject RE: Include directive behavior
Date Wed, 17 Nov 2004 16:18:55 GMT
Shinobu,

Thank you for the reply.  I'll file an issue and see what the developers
say.  Meanwhile, I did get a workaround working with the userdirective.
One thing I forgot to mention was that I intended to override the system
"include" directive with my userdirective, and the documentation did not
mention if this was possible.
However, I found the answer which I'll submit to the list for the
benefit of the archives. :-)

To set a userdirective at runtime, use:
VelocityEngine.setProperty("userdirective","myDirectiveClass")
Before calling VelocityEngine.init().

In order to override a system directive, make myDirectiveClass.getName()
return "include" (or the name of whatever system directive you're
replacing).

Now, in your templates, when you call #include, it will execute your own
directive instead of Velocity's Include directive.
---------------------

Hi Jason,

> However, renderOutput() will throw a ResourceNotFoundException if the
> Included file does not exist (the exception is caught in renderOutput,
> but thrown again).
> This exception is not handled by render(), and so the exception gets
> passed up the call stack without outputErrorToStream() ever being
> called.
> 
> So my first question is:  is this a bug, or is there a reason to not
> allow writing an error to the output stream in this case?
I don't know about this.  Maybe it should be discussed in the developer
list.
## Or you can just file an issue and see what happens.  B)

> Question 2:  I can modify the Include directive, but is there a way to
> configure Velocity at runtime to use the custom directive, so that I
can
> continue using an unmodified velocity jar?
> I'm using setProperty() to override velocity.properties with values
that
> are in my application's config, but I can't see a way to do that to
> override what's in directive.properties.
Try userdirective.
  http://jakarta.apache.org/velocity/developer-guide.html#FAQ3

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <shinobu.kawai@gmail.com>



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


Mime
View raw message