In this particular case, the component factory knows the component types
and it can "inject" a global template with all the rendering templates +
1 which makes the switch.
However, I think it will be useful to have the possibility to register
templates as function and be able to call(with a directive called
#function or #invoke) them with the current template context.
It is just a matter of wrapping the current context with a different
one, override the function parameters in the context, render the
function template in the current Writer.
There will be some overhead(preparing the new context, and merge the
template), but the feature will benefit of function reload on
change(since is a template) and will allow dynamic calling of a template.
In my case, since I want to be as fast as possible, I will generate the
macros but I will give it a try and implement also the function way. I
will do a benchmark to see how much overhead I will add with this approach.
Thanks for your support.
Christopher Schultz wrote:
Adrian,
Adrian Tarau wrote:
I think it is a question for the dev's list, since it involves
creating a new feature - a new directive - (or asking about velocity
internals).Is not a question about how to use velocity. My bad if I'm
mistaken.
I suppose it could go either way. I see this as asking if there's a
good way to do what you're trying to do. It may not actually need a
code change. Of course, what you /proposed/ requires code changes, but
perhaps there's a way to do it another way...
The possibilities are limited by default, around 12(the standard
Swing components), but the infrastructure is flexible so any time a
new component type can be plugged in(the component factory registers
a new #macro for every component type).
I would like to avoid those calling #if 12 times and anyway, it
breaks the plug&play model.
If your component factory registers new macros when new component
types are added, perhaps you could have that same factory register a
macro that does your 12-way check. Something like this:
#renderComponent($component)
#if($component.type == 'label')
...
#elseif($component.type == 'whatever')
...
#end## switch(component.type)
#end## macro renderComponent
Then, in your templates, you always use:
#renderComponent($component)
Your templates are clean, your infrastructure takes care of the
messiness, and the devs here don't have to figure out how to retrofit
the Velocity language parser to allow for something like:
#('render' + $component.type)($component)
Another alternative might be to use a "tool" instead of a directive.
But that gets back to why Velocity.invokeVelocimacro won't work for
you (why doesn't it work, again?).
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]