File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes The attribute directive in tag files. 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 "The attribute directive in tag files." Watch "The attribute directive in tag files." New topic
Author

The attribute directive in tag files.

Supun Dewaraja
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Hi all,
If an attribute is not declared using the attribute directive where will it be created tagScope or in the including page's pageScope ?
if it is declared using an attribute directive which scope is it attached to ?

SCJP 5.0(90%), SCWCD 5.0(94%)
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Supun. If we don't declare attribute directive in tag file, and if try to call through jsp, exception will occur.
If declared in tag file, the attribute will be set in page scope.
Supun Dewaraja
Greenhorn

Joined: Sep 16, 2007
Posts: 9
my problem is does the tag file have its own page scope or is it the including file's page scope. Because all tag attributes go out of scope when the tag completes how can that happen if its an attribute bound to the including file's page scope ?
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Supun. Can you please explain your problem with an example?
Supun Dewaraja
Greenhorn

Joined: Sep 16, 2007
Posts: 9
This is my jsp


and my tag file sri.tag in "/WEB-INF/tags" is


this prints

The subtitle is


what could be the problem.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Supun.
Here 'subTitle' will not be visible in jsp file. The attribute 'subTilte' will be set in tag file with page scope. It will visible to only sri.tag file.
If you see the generated source file it will be clear.
Supun Dewaraja
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Oh ok got it so the body is evaluated against the main jsp page scope.
Thanks for the help Chinmaya
Bruce Phillips
Greenhorn

Joined: Nov 20, 2001
Posts: 13
I believe you need to use the <%@ variable directive. See:

http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html#bnamj
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Bruce. Can you please tell, the purpose of variable directive?
Supun Dewaraja
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Yeah that worked thanks Bruce I am wondering whether this is on the exam Head First slightly mentions the variable directive in the questions though.
here is the jsp


and the sri.tag


It produced the result
The subtitle is The Da Vinci Code


The variable directive is used to pass back values (kind of like a return from a method) to the main JSP from the tag file.
more here webpage
Bruce Phillips
Greenhorn

Joined: Nov 20, 2001
Posts: 13
Glad you figured out how to use it.

The variable directive does show up on my Enthuware SCWCD mock exams.

Here's another example for people to use (this one uses the name-from-attribute and scope of "AT_BEGIN")

YearBorn.tag



TagFileTest.jsp


The <@ variable name-from-attribute="var" scope="AT_BEGIN" alias="yearBorn" %> means when the tag is called the value for the var attribute will be the name of the variable to set in the calling page. The alias="yearBorn" means in the tag file whatever value is given to yearBorn will be the value given to the var attribute's value in the calling page (in my example the var="brithYear".

The scope="AT_BEGIN" means that the birthYear value will be available from the beginning of the call to the tag file on through the rest of the calling page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The attribute directive in tag files.