• 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

TagExtraInfo

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon,
Thanks for the reply. That makes perfect sense. I appreciate the info.
-MLA
 
reply
    Bookmark Topic Watch Topic
  • New Topic