Hi All,
Is there some kind of way in the velocity API to implement filters that
can operate on objects on the context? Specifically, say object person
is on the context, if person.name is called, and the getName() method
has an annotation on it, I want to be able to transform the value
displayed on the rendered output.
Is this possible?
Thanks,
James
[Velocity-user] Filters?
| Tweet |
|
Search Discussions
-
Nathan Bubna at Nov 6, 2008 at 6:16 pm ⇧
Sounds like something that the ReferenceInsertionEventHandler might be
able to do:
http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Event_Handlers
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/app/event/ReferenceInsertionEventHandler.htmlOn Thu, Nov 6, 2008 at 6:28 AM, James Carr wrote:---------------------------------------------------------------------
Hi All,
Is there some kind of way in the velocity API to implement filters that
can operate on objects on the context? Specifically, say object person
is on the context, if person.name is called, and the getName() method
has an annotation on it, I want to be able to transform the value
displayed on the rendered output.
Is this possible?
Thanks,
James
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
-
James Carr at Nov 7, 2008 at 3:18 pm ⇧
Thanks, but that doesn't quite do what I need... it seems that it only
gets the value returned by the method call and has no reference to the
object the call was made on. For example, if my template has
$foo.bar
I just get the following:
"$foo.bar"
"Some string returned by method bar"
Is there any way to get a reference to $foo in this case and intercept
the result returned by getBar()?
Thanks,
James
-----Original Message-----
From: Nathan Bubna
Sent: Thursday, November 06, 2008 12:16 PM
To: Velocity Users List
Subject: Re: Filters?
Sounds like something that the ReferenceInsertionEventHandler might be
able to do:
http://velocity.apache.org/engine/devel/developer-guide.html#Configuring
_Event_Handlers
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/app/
event/ReferenceInsertionEventHandler.htmlOn Thu, Nov 6, 2008 at 6:28 AM, James Carr wrote:---------------------------------------------------------------------
Hi All,
Is there some kind of way in the velocity API to implement filters that
can operate on objects on the context? Specifically, say object person
is on the context, if person.name is called, and the getName() method
has an annotation on it, I want to be able to transform the value
displayed on the rendered output.
Is this possible?
Thanks,
James
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
-
Nathan Bubna at Nov 7, 2008 at 6:09 pm ⇧
Ah. Well, if the result returned by getBar() is an object type under
your control, then with 1.6-beta2, you can have it implement this
interface:
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/runtime/Renderable.html
which allows rendering that doesn't go through toString().
If the class of that is not under your control or you don't like the
above method, then you may be able to achieve your result via a custom
Uberspect implementation.
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/util/introspection/Uberspect.html
The default setting in the velocity.properties is:
runtime.introspector.uberspect =
org.apache.velocity.util.introspection.UberspectImpl
the easiest thing is usually to replace that with a subclass of
UberspectImpl. and with 1.6-beta2, there is support for chaining and
linking Uberspects as well.
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/util/introspection/ChainableUberspector.html
If you went the custom Uberspect route, then you should be able to
turn a getBar() call into something else.On Fri, Nov 7, 2008 at 7:17 AM, James Carr wrote:---------------------------------------------------------------------
Thanks, but that doesn't quite do what I need... it seems that it only
gets the value returned by the method call and has no reference to the
object the call was made on. For example, if my template has
$foo.bar
I just get the following:
"$foo.bar"
"Some string returned by method bar"
Is there any way to get a reference to $foo in this case and intercept
the result returned by getBar()?
Thanks,
James
-----Original Message-----
From: Nathan Bubna
Sent: Thursday, November 06, 2008 12:16 PM
To: Velocity Users List
Subject: Re: Filters?
Sounds like something that the ReferenceInsertionEventHandler might be
able to do:
http://velocity.apache.org/engine/devel/developer-guide.html#Configuring
_Event_Handlers
http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/app/
event/ReferenceInsertionEventHandler.htmlOn Thu, Nov 6, 2008 at 6:28 AM, James Carr wrote:---------------------------------------------------------------------
Hi All,
Is there some kind of way in the velocity API to implement filters that
can operate on objects on the context? Specifically, say object person
is on the context, if person.name is called, and the getName() method
has an annotation on it, I want to be able to transform the value
displayed on the rendered output.
Is this possible?
Thanks,
James
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Related Discussions
Discussion Navigation
| view | thread | post |
Discussion Overview
| group | user
|
| categories | velocity |
| posted | Nov 6, '08 at 2:29p |
| active | Nov 7, '08 at 6:09p |
| posts | 4 |
| users | 2 |
| website | velocity.apache.org |
2 users in discussion
Notice: Undefined index: I in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 94
Notice: Undefined index: 0 in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 97
Notice: Undefined index: 0 in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100
Notice: Undefined index: I in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 94
Notice: Undefined index: 0 in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 97
Notice: Undefined index: 0 in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100
Notice: Undefined index: I in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 97
Notice: Undefined index: O in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100
Notice: Undefined index: I in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 97
Notice: Undefined index: O in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100
