速度事件处理程序
在速度中,当你执行 $object.variable 时,如果它无法找到 getter 函数 访问它或者 getter 返回 null。它只会在页面上显式显示 $object.variable
我知道有一个安静的引用,但我不想添加!对数千个变量进行签名。
我尝试过 InvalidReferenceEventHandler、NullValueHandler 他们都没有被调用。
我想知道是否有专门类型的事件处理程序用于此目的。
非常感谢
in velocity, when you do $object.variable if it not be able to find the getter function to
access it or the getter returns a null. it will just show $object.variable explicitly on the page
I know there is a quiet reference, but I don't want to add ! sign to thousands of variables.
I have tried InvalidReferenceEventHandler, NullValueHandler they all didn't get called.
I wander is there a specific type of Eventhandler for this.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上述似乎也是一个有效的选择。然而,这里有另一个选择:
您还需要将以下内容添加到velocity.properties文件中:
您可能会对结果感到惊讶,因此可能需要根据您的需求进行微调。
The above seems to be a valid choice as well. However here is another option:
You'll also need to add the following to your velocity.properties file:
You might be surprised at the results though, so it will likely need fine-tuning dependent upon your needs.
我基于 Engine-1.7 代码。
似乎当调用无效方法时,会调用实用方法 EventHandlerUtil.invalidGetMethod 。此方法创建一个新的 InvalidGetMethodExecutor (这是 InvalidReferenceEventHandler 上的内部类)。最终,这会链接到对 invalidReferenceHandlerCall 的调用,该调用最终会迭代已定义的任何 handlerIterators。不幸的是,我对 Velocity 的内部了解不够,无法告诉您如何注入这些值。我的猜测是,用户列表将建议一种覆盖此行为的方法,或者建议使用/实现自定义工具。
编辑:
根据开发人员指南,您可以执行以下操作。您需要编写一些代码来处理它,但这应该不会太困难:
Pluggable Introspection
此属性设置“Uberspector”,即处理 Velocity 的所有自省策略的自省包。您可以指定以逗号分隔的 Uberspector 类列表,在这种情况下,所有 Uberspector 都会被链接起来。默认的链接行为是为所有提供的 uberspector 中的每个内省调用返回第一个非空值。您可以通过子类化 org.apache.velocity.util.introspection.AbstractChainableUberspector (或直接实现 org.apache.velocity.util.introspection.ChainableUberspector)来修改此行为(例如限制对某些方法的访问)。这允许您为 Uberspection 创建更有趣的规则或模式,而不仅仅是返回第一个非空值。
I'm basing this off of Engine-1.7 code.
It seems that when an invalid method is called that the utility method EventHandlerUtil.invalidGetMethod is called. This method creates a new InvalidGetMethodExecutor (this is an inner class on InvalidReferenceEventHandler). Eventually this chains down into a call to invalidReferenceHandlerCall which eventually iterates over any handlerIterators which have been defined. Unfortunately I don't know enough about the internals of Velocity to tell you how to inject these values though. My guess is that the user list will suggest a way to override this behavior or a suggestion will be to use / implement a custom tool.
Edit:
According to the Developer Guide you can do the following. You'll need to write some code to deal with it, but it shouldn't be too difficult:
Pluggable Introspection
This property sets the 'Uberspector', the introspection package that handles all introspection strategies for Velocity. You can specify a comma-separated list of Uberspector classes, in which case all Uberspectors are chained. The default chaining behaviour is to return the first non-null value for each introspection call among all provided uberspectors. You can modify this behaviour (for instance to restrict access to some methods) by subclassing org.apache.velocity.util.introspection.AbstractChainableUberspector (or implementing directly org.apache.velocity.util.introspection.ChainableUberspector). This allows you to create more interesting rules or patterns for Uberspection, rather than just returning the first non-null value.