File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes TagExtraInfo Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "TagExtraInfo" Watch "TagExtraInfo" New topic
Author

TagExtraInfo

Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
Hi all,
I think I am missing something and was wondering if anyone could offer some light on this subject. Whenever I have a java object in a Tag class that I want to make available to the JSP page, such as a String called userName, I add a line to my doEndTag method which says something like :
pageContext.setAttribute("userName",userName);
and I add a class that extends TagExtraInfo and override the getVariableInfo method with a method that will contain a line something like:
VariableInfo info1 = new VariableInfo( "userName", "String", true, VariableInfo.AT_END);
and finally update the tld with the specified TEI.
The question is why is it necessary to do all of these things? What are the advantages to this versus just setting the attribute in the doEndTag method like:
pageContext.setAttribute("userName",userName, PAGE_SCOPE);

?
Thanks in advance for clarifying the subtle or not so subtle differences in these methodologies.
-MLA


Sun Certified Programmer for the Java 2 Platform 1.4
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1860
The key difference is that by using your TEI class, a variable will be declared on the page so that you can access it directly with something like <%= userName %>.
However, if you don't use a TEI class and simply set the attribute, you can only access the object by <%= page.getAttribute("userName") %>.
JSP 2.0 fixes much of this by allowing an easy way to access scoped attributes and hence reduces the need to use scripting variables at all.
Simon
Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
Simon,
Thanks for the reply. That makes perfect sense. I appreciate the info.
-MLA
 
 
subject: TagExtraInfo
 
Threads others viewed
About TagExtraInfo class?
TagExtraInfo Question
Help with a TagExtraInfo class
TEI TagExtraInfo - Use of?
set the custom tag variable
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture