• Post Reply Bookmark Topic Watch Topic
  • New Topic

Information DURING rendering of custom tag

 
Frank Zammetti
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all... is there any way to gain information while rendering a custom tag such as the parent of the tag, or the previous tag rendered?

I have a situation where I have a taglib which I cannot alter the source for... What I want to do is insert a quick snippet of Javascript following any tag that has a specific attribute, so I was thinking of creating my own tag for this.

So, originally I might have...

<custom:theTag attr="yes" />

... which maybe for instance renders...

<span id="s1" Hello!</span>

...and what I want is to be able to do...

<custom:theTag myid="s1" />
<newCustom:newTag />

...which will render...

<span id="s1" Hello!</span><script>s1.style.color='#ff0000';</script>

So clearly in the code that renders that newTag, I have to be able to access the myid attribute of the previous tag. Anyone think of a way to do that? Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
such as the parent of the tag, or the previous tag rendered?


Parent tag, yes. Previous tag, no.

Perhaps you could do what you want in other ways. Off the cuff:

1) Wrap the target tag in your own, intercepting the attribute (so you know what it is), and emit the JS in the end hamdler.

2) Instead of hard-coding the "s1" id, supply it from a scoped variable so your page knows what it is. (assumes the id attribute is rt-enabled).
 
Frank Zammetti
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The wrapping idea is an interesting one... How does one "interecept the attribute" though? That's a new idea to me.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Override the set method so you can store the value in your tag, then call the super-class set method.
 
Frank Zammetti
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah... I had a different meaning for "wrap" in my mind... I thought you meant something like...

<myWrapperTag><originalTag/></myWrapperTag>

...and that I would be able to somehow... eh, you know, I'm not quite sure *what* I was thinking beyond that!

I gotcha now though, a wrapper class. That won't work in my case because it would require changing the TLD, which is something else I want to avoid. Sounds like I'm pretty well SOL... My other option was a tag that emits Javascript that traverses the DOM looking for tags with the specific attribute I know about, and updating the tag accordingly. I wanted to keep this from spilling client-side to *that* degree though, but I may not have a choice.

Thanks Bear!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would require changing the TLD


You were talking about creating your own custom tag to begin with. How would this be different? The TLD of the "orginal" tag would be unchanged, you'd just be adding a new tag to your own TLD.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!