aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark ""declare" element in "variable" element of TLD" Watch ""declare" element in "variable" element of TLD" New topic
Author

"declare" element in "variable" element of TLD

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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 ]

[My Blog]
All roads lead to JavaRanch
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Both.
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Thanks Christophe!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "declare" element in "variable" element of TLD