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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to