Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TagExtraInfo

 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon,
Thanks for the reply. That makes perfect sense. I appreciate the info.
-MLA
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!