Re: Nested tags attribute clash
Erwin DSouza wrote: Hi Hans, Sorry to bother you again with this old thread, but I hadn't thought of all the implications of your suggestion until now. I was asking about how to avoid attribute-name clashes in nested tags, and you suggested using: 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... 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). I *do* need to access the attributes in scripting code. But how do I add the new variable dynamically to the TagExtraInfo class? How does it help if I add var to the TEI? (I need foo and bar to be variables that I can access in my scripting code) Is this possible? Yes it is. As to how, read a book, like mine :-) Just kidding, even though I do recommend that anyone doing JSP development read at least the specification. There are many things that you just can't figure out just by looking at the APIs. Anyway, here's a TEI that tells the container to create a variable with the name supplied by the page author as the id attribute value (you should use id when you create a scripting variable, following the convention from jsp:useBean; var is a name convention established by JSTL for variables saved only in a JSP scope): public class MyTagTEI extends TagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo(data.getAttributeString(id), com.mycompany.SomeType, true, VariableInfo.AT_END) } } } The variable is of type com.mycompany.SomeType and made available after the closing tag for the action element (AT_END). If you use a JSP 1.2 container, you can replace the TEI with this declaration in the TLD: tag namemyTag/name tag-classcom.mycompany.MyTag/tag-class variable name-from-attributeid/name-from-attribute variable-classcom.mycompany.SomeType/variable-class declaretrue/declare scopeAT_END/scope descriptionThis variable contains .../description /variable ... /tag Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com JavaServer Pageshttp://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
Re: Nested tags attribute clash
Hi Hans, Sorry to bother you again with this old thread, but I hadn't thought of all the implications of your suggestion until now. I was asking about how to avoid attribute-name clashes in nested tags, and you suggested using: 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... 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). I *do* need to access the attributes in scripting code. But how do I add the new variable dynamically to the TagExtraInfo class? How does it help if I add var to the TEI? (I need foo and bar to be variables that I can access in my scripting code) Is this possible? Thanks a ton. -Erwin === 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
Nested tags attribute clash
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... TIA! -Erwin === 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
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 Pageshttp://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
Re: Nested tags attribute clash
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 Pageshttp://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