http://wiki.apache.org/velocity/VelocityFAQ :
Q: How can I access my public object fields in my templates?
A: You currently have three options:
Wrap your object with FieldMethodizer
Configure your VelocityEngine to use a custom uberspector such as PublicFieldUberspect
Lobby the-dev speed list to add self-analysis of the open field as the default backup if no suitable method is found :)
FieldMethodizer only works with public static fields.
PublicFieldUberspect sample code is pretty old, and it just fails with an error in non-existent fields.
And forget about the lobby on the developer list. )
Meanwhile, there is a good caching implementation of UberspectPublicFields in the current high-speed trunk . Unfortunately, there has been no active development for many years , and no plans for the next release are published. One of them would have to build it himself and link it in a private repository.
Another alternative is the scala bonus compatible plug, available in the central maven repository: http://maven-repository.com/artifact/com.sksamuel.scalocity/scalocity/0.9 .
Inclusion instead of the usual speed dependence:
<dependency> <groupId>com.sksamuel.scalocity</groupId> <artifactId>scalocity</artifactId> <version>0.9</version> </dependency>
Then just add to velocity.properties :
runtime.introspector.uberspect = org.apache.velocity.util.introspection.UberspectPublicFields, org.apache.velocity.util.introspection.UberspectImpl
The UberspectImpl that UberspectImpl fixed with additional support for scala properties and requires an 8 MB scala jar.
In the end, I simply interned the following classes from the speed trunk into my own project:
org.apache.velocity.runtime.parser.node.PublicFieldExecutor org.apache.velocity.runtime.parser.node.SetPublicFieldExecutor org.apache.velocity.util.introspection.ClassFieldMap org.apache.velocity.util.introspection.Introspector. apache.velocity.util.introspection.IntrospectorBase org.apache.velocity.util.introspection.IntrospectorCache org.apache.velocity.util.introspection.IntrospectorCacheImpl org.apache.velocity.util.introspection.UberspectPublicFields
They work great with Velocity 1.7.