Question

Can Velocity be configure to fail (i.e. throw an Exception) when a $var is undefined.

Such a "fail-fast" strategy would help in our testing cycles.

Was it helpful?

Solution

In Velocity 1.6 you can add the following property to your velocity.properties

runtime.references.strict = true

Edit: Full list of configuration is available here: http://velocity.apache.org/engine/devel/configuration.html

OTHER TIPS

You can register an event handler which tells Velocity to throw an exception on an undefined reference

You could switch to FreeMarker. It throws exceptions on missing fields, and, invalid types.

Not only that the exceptions thron are precise and readable. ' Missing field FOO at line 234 in BAR.ftl ' etc. etc.

I would absolutly recommend Freemarker over any other templating system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top