Re: Nested Java directives - best practice on how to make values available to inner directive?

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Friday, February 1, 2008, 9:47:20 AM, Alistair Israel wrote:

> On Jan 31, 2008 6:09 PM, Jonathan Revusky <[email protected]> wrote:
>
>> Yes, well, the problem is that, within the nested body associated with a
>> macro, you are not actually within the macro -- at least from a variable
>> namespace resolution POV.
>
> Looking through the code again, that makes sense now.
>
>
>> Well, I don't think you need this to be a global variable, i.e. visible
>> from all namespaces. Probably, you could use:
>>
>> env.getCurrentNamespace().put("name", name);
>
> That actually worked pretty well. Thanks.
>
> Next thing I tried to do was rewrite my 'top level' @form macro as a
> regular FTL macro. In that macro, I assigned "formName":
>
> In "forms.ftl":
> <#macro form name action method="POST">
> <#assign formName = name/>
> <#nested/>
> </#macro>
>
> In TextInputDirective, calling env.getLocalVariable("formName")
> returned null. I was able to get the value by simply using
> env.getVariable(), so I guess that's another 'workaround'.
>
> But when I tried to include "forms.ftl" as f, and started using
> <@f.form ...><@textInput ...></@form>, TextInputDirective suddenly
> couldn't see "formName" again - whether using getLocalVariable(),
> getCurrentNameSpace().get() or just getVariable().

But do f.form and textInput belong to the same namespace? I don't
think so. Anyway, Jonathan, I wonder if how is it decided which
namespace a TemplateDirectiveModel or TemplatTransformModel or
TemplateMethodModel belongs to... after all, they are not defined in a
template. Yet another asymmetry between a Java-implementation and an
FTL-implementation of a directive/function?

> At this point, I think I'll settle with either one of the two
> workarounds that actually worked - at least until 2.4 comes out,
> maybe.
>
> - Alistair A. Israel

-- 
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.