【问题标题】:Apache Velocity Quiet Reference Notation as default behaviourApache Velocity Quiet Reference Notation 作为默认行为
【发布时间】:2011-06-06 16:48:42
【问题描述】:

当 Velocity 遇到未定义的参考时,它的正常行为是输出参考的图像。例如,假设以下引用作为 VTL 模板的一部分出现”示例:

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

是否可以配置默认行为,以便我仍然可以编写 $email 并且它隐含地是一个安静的符号?

【问题讨论】:

    标签: java velocity template-engine


    【解决方案1】:

    是的。有一个事件处理程序在发现无效引用时被调用。它称为 InvalidReferenceEventHandler。您需要让事件处理程序返回一个空字符串。

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

    有关如何创建和注册事件处理程序的详细信息,请参阅 Velocity 开发人员指南。但简而言之,实现 InvalidReferenceEventHandler,然后在设置 VelocityEngine 时包含此属性。

    eventhandler.invalidreferences.class=com.something.youreventhandlerclass
    

    【讨论】:

    猜你喜欢
    • 2015-04-29
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    相关资源
    最近更新 更多