I have a feeling that the problem you are facing is that your tags are reliant on each other putting variables into the PageContext scope to pass variables back and forth to each other. My suggestion is to only use variables at the PageContext scope when the user of the tag specifically requests for you to create an object to use later for their own purpose. You should instead pass these variables down/up tags using the findAncestorWithClass method and calling parent methods to set/retrieve any needed objects.
-----Original Message----- From: Hans Bergsten [mailto:[EMAIL PROTECTED]] Sent: Friday, March 15, 2002 11:07 AM To: [EMAIL PROTECTED] Subject: Re: Nested tags attribute clash Erwin DSouza wrote: > Hi list, > > I was in the process of designing tags for my pages when i came > across a problem. > I need to display a list of subjects, and for each subject, a list > of sub-sections, and for each sub-section a list of topics. > I intend to use nested tags for this. But all 3 tags would > introduce a variable named "name" into the pagecontext. Wouldn't > these variables clash in the jsp? How do I go about having a > simple nested design without having any attribute-name clashes? > I know, the simplest solution is to have different attribute names > for each tag, but does anyone have a better cleaner approach, > wherein I don't have to carefully forsee the usage of all my > tags? > > I hope I wasn't too unclear... I assume you mean something like this: <!-- Create variable "foo" --> <mytags:foo> <!-- Create variable "foo" again; doesn't work --> <mytags:foo> ... </mytags:foo> </mytags:foo> The easiest solution is to let the page athor specify the variable name: <!-- Create variable "foo" --> <mytags:foo var="foo"> <!-- Create variable "bar" --> <mytags:foo var="bar"> ... </mytags:foo> </mytags:foo> If you don't need to access the value through a scripting variable, just save it as an attribute in one of the scopes using PageContext.setAttribute() with the name specified as the "var" attribute (this approach is getting more common and is used by the upcoming JSP Standard Tag Libray, JSTL: <http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html>). If you *do* need to access the value through scripting code, you can tell the container to use the "var" attribute value for the scripting variable using either a TagExtraInfo class (JSP 1.1 and JSP 1.2) or using the <variable> element in the TLD (JSP 1.2). Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com JavaServer Pages http://TheJSPBook.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
