Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just did this with spring and velocity:</p> <p>I had problems getting velocity to pick up my event handler, in the end specifying it in the servlet xml file:</p> <pre><code>&lt;bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"&gt; &lt;property name="resourceLoaderPath" value="WEB-INF/templates"/&gt; &lt;property name="velocityPropertiesMap"&gt; &lt;map&gt; &lt;entry key="eventhandler.include.class"&gt;&lt;value&gt;com.velocity.events.OptionalIncludeEventHandler&lt;/value&gt;&lt;/entry&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>It simply would not accept me putting it in the properties file - it would instantiate the class, but not register it as an event listener. very frustrating.</p> <p>The class itself is simple, a quite blatant rip off from the existing velocity class "org.apache.velocity.app.event.implementIncludeNotFound". The existing velocity implementation checks for the existance of the file, and if not present returns a configurable alternative (default: notfound.vm). </p> <p>Mine is exactly the same except it returns null if the file does not exist, causing the parser to skip this include / parse directive:</p> <pre><code>public class OptionalIncludeEventHandler implements IncludeEventHandler, RuntimeServicesAware { private RuntimeServices rs; @Override public void setRuntimeServices(RuntimeServices rs) { this.rs = rs; } @Override public String includeEvent(String includeResourcePath, String currentResourcePath, String directiveName) { return rs.getLoaderNameForResource(includeResourcePath) != null ? includeResourcePath : null; } } </code></pre> <p>Works like a charm.</p> <p>Hope it's useful.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload