• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"declare" element in "variable" element of TLD

 
Meng Tan
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May I know what is the meaning of the <declare> element in the <variable> element of a TLD?
It can be either "true" or "false".
Thanks!
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may need to access some values set in a tag, and to do so you can use the "variable" tag. The "declare" attribute will force the container to declare a new variable in the calling page, so that the page can access the value set in the tag. "declare" defaults to true. If "declare" is set to false, the variable will not be declared by the container, so it is assumed that the variable already exists in the calling page.

For example (using the variable directive of a Tag File), the following tag will force the container to declare a new variable (java.lang.String extVar ;) in the JSP calling the tag, just before the tag is being used :


If the declare was set to false, this variable would not be declared, assuming there's already an existing variable of the same name.
[ July 28, 2008: Message edited by: Christophe Verre ]
 
Meng Tan
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe for your detailed explanation!

Can I also ask the another question?
How can the variable be accessed by the calling page)?
Is it by means of expression or EL or both?
Thanks!
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both.
 
Meng Tan
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic