Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Velocity Quiet Reference Notation as default behaviour

When Velocity encounters an undefined reference, its normal behavior is to output the image of the reference. For example, suppose the following reference appears as part of a VTL template" example:

<input type="text" name="email" value="$!email"/>

Is it possible to configure a default behaviour, so that I could still write $email and it's implicitly a quiet notation?

like image 468
caeycae Avatar asked Nov 04 '22 20:11

caeycae


1 Answers

Yes. There's an event handler which is called when an invalid reference is found. It's called InvalidReferenceEventHandler. You'll want to have the event handler return an empty string.

public Object invalidGetMethod( Context context, 
                                    String reference, 
                                    Object object, 
                                    String property, 
                                    Info info)
{
    return "";
}

Consult the Velocity Developer's Guide for details on how to create and register an event handler. But in a nutshell, implement InvalidReferenceEventHandler and then include this property when setting up your VelocityEngine.

eventhandler.invalidreferences.class=com.something.youreventhandlerclass
like image 93
Will Glass Avatar answered Nov 11 '22 14:11

Will Glass