Hallo Daniel, thank you very much for you help!! I will test this today.
>>> Well, that's one of the things why a dedicated feature would be >>> better. In JSP Custom Taglib technology you will found a feature like this: Inside e.g. a select-tag definition you can write the following to find the next matching parent tag: Group nextParentGroupTag = (Group) findAncestorWithClass(this, Group.class); It returns null if no "group" tag in parents path was found otherwise you have access to the attributes and methods of the found "group" tag. > Gesendet: Samstag, 05. Dezember 2015 um 14:08 Uhr > Von: "Daniel Dekany" <[email protected]> > An: "Ingo Mahnke" <[email protected]> > Cc: [email protected] > Betreff: Re: Aw: Re: Communication between directives > > Saturday, December 5, 2015, 12:18:17 PM, Ingo Mahnke wrote: > > > > > Thank you, global variables Sounds good. > > What's with cascading? > > > > <@group name="qname" label="Header" render="collapse" id="header"> > > <@select name="kjkjk"/> > > <@group name="def" label="SubHeader" render="collapse" > > id="subheader"> > > <@select name="abck"/> > > </@group> > > <@select name="kjkjk2"/> > > </@group> > > Well, that's one of the things why a dedicated feature would be > better, but anyway, it's still possible, even if it's a bit verbose. > For example, you could have a last_myLib_group_name: > > <#macro group name> > <#global last_myLib_group_name=myLib_group_name!> > <#global myLib_group_name=name> > .. > <#nested> > .. > <#global myLib_group_name=last_myLib_group_name> > </#macro> > > One caveat you will run into here is that for the outermost group, the > last #global assignment will restore myLib_group_name to be "" instead > of to be non-existant... so then that's something you have to consider > in @select: an empty name means you have no enclosing @group, which > should just be an error, instead of going on with an empty name. > > But if I was heavily relying on something like this, I would consider > using some helper directive for this, that can manage a "stack" of > values (an List technically). > > -- > Thanks, > Daniel Dekany > > > >> Gesendet: Samstag, 05. Dezember 2015 um 01:07 Uhr > >> Von: "Daniel Dekany" <[email protected]> > >> An: "Ingo Mahnke" <[email protected]> > >> Cc: [email protected] > >> Betreff: Re: Communication between directives > >> > >> Friday, December 4, 2015, 8:44:12 PM, Ingo Mahnke wrote: > >> > >> > Hallo! > >> > I am new to freemarker and I have one question perhaps sombody can help > >> > me. > >> > I have two own directives written in Java and one Template: > >> > > >> > > >> > <@group name="qname" label="Header" render="collapse" id="header"> > >> > <@select name="kjkjk"/> > >> > </@group> > >> > > >> > When I am inside the execute method of "select" I need access to > >> > the next parent "group"-Element and I need the > >> > value of the "name" attribute. Is this kind of communication between > >> > directives possible? > >> > >> There's no dedicated feature for it (there should be...), but it's > >> still possible. Both kind of directives (one implemented as an FTL > >> macro, the other in Java as TemplateDirectiveModel, I assume) can read > >> and write the so called global variables. Global variables live inside > >> the Environment object, of which a new one is created for each > >> Template.process call. In FTL, you create/modify globals as > >> <#global myVar = someValue>, and just read them as any other variable > >> (assuming it's not shadowed by another, but then you can still use > >> .globals.myVar). In Java, you can use Environment.getGlobalVariable > >> and setGlobalVariable. Of course, you should chose a sufficiently > >> unique global variable name, like myLib_group_name. > >> > >> > Thank you! > >> > Ingo > >> > >> -- > >> Thanks, > >> Daniel Dekany > >> > >> > >> --- > >> This email has been checked for viruses by Avast antivirus software. > >> https://www.avast.com/antivirus > >> > >> > > > > -- > Thanks, > Daniel Dekany > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > >
