• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tag getParent() for tag files?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not aware of any manual for tag files. What is your source?

Gili
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone have any idea?

Gili
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at chapter section 14.8
http://csajsp-chapters.corewebprogramming.com/CSAJSP-Chapter14.pdf
 
Gili Tzabari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic