This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Tag getParent() for tag files?  RSS feed

 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible to getParent() to get the parent tag from within a tag file? I have a tag that should only be used within a specific parent tag and I want to ensure this somehow. Any ideas?

Thanks,
Gili
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to be precise, there's a way to chase all the way back up the tag stack in case the enclosed tag isn't the immediate child of the enclosing parent.

As for the exact code, I don't remember, so I'd have to RTFM.

Or you will.
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not aware of any manual for tag files. What is your source?

Gili
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not aware of any manual for tag files.


The JSP 2.0 Specification is available from Sun's site.
[ December 21, 2004: Message edited by: Bear Bibeault ]
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just flipped through the specification. It doesn't seem to discuss this matter at all. The only thing that *might* help is that tag files have access to a bunch of implicit variables including JspContext but I don't see how one can use any of them to find the enclosing tag. They all seem to operate on JSP concerns, not tag concerns.

Gili
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone have any idea?

Gili
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,

I know how to getParent() from within a tag Object, but what I meant is, how do I do the same from witin a tag file (that is .tag and .tagx files)? I can't seem to find a way.

Gili
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering that scriplets are disallowed in tag files, I suspect that this is not something that was deemed useful.
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand. What does scriptlet support have anything to do with nested classes? That is, if I wanted to implement <if> <else> tags inside a <condition> enclosing tag, why wouldn't I be able to do this using .tagx files?

Gili
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you could elaborate on exactly what it is you are trying to achieve? A getParent() call isn't going to be available or useful in a scriptless environment. Are you just trying to get access to attributes of the parent tag? Ensure nesting? Other?
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to ensure nesting: that is, "if" and "else" may only be used within "condition", otherwise throw an exception.

Gili
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then in my opinion you are using a tack hammer where a ball-peen is required.

Tag files are primarily intnded to replace tags whose primary output is pure JSP/HTML -- removing the need to build up HTML in Java code. For the type of processing you are intending you would be better off implementing the tag as a Java class extending either the new "simple" or the "classic" tag support library.

If you do insist on using tag files, I would have the parent tag place information on the page context that the child tags could access and check with JSTL tags.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!