aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Page-scope vs tag-scope 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 "Page-scope vs tag-scope" Watch "Page-scope vs tag-scope" New topic
Author

Page-scope vs tag-scope

Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

Hi, I'm reading "Head First Servlets and JSP" and have a question concerning page-scope vs tag-scope. I'm having trouble with one of the Mock Exam questions:

Chapter 10 Mock Exam, answer to question 18, p.599:
"Which are true about the Tag File model?"

One of the answers is:
"For each attribute declared and specified in a Tag File, the container creates a page-scoped attribute with the same name."

Shouldn't it read "creates a tag-scoped attribute"? A page-scoped attribute would be visible outside of the tag, wouldn't it? For example:

The JSP:

The generated page:

This isn't what really happens--what happens is it can't find ${foo}, so it prints an empty string. But isn't this what should happen if tag attributes are page-scoped? Thanks!


SCJP 6 || SCWCD 5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It is called page scope (what is tag scope ?), but the context is different. It's not the same page context as the page calling the tag. That's why you don't see the value in your JSP. Check the JSP specification, JSP.8.3 Semantics of Tag Files :

  • The tag file implementation must create and maintain a second instance of JspContext called a JSP Context Wrapper. If the Invoking JSP Context is an instance of PageContext, the JSP Context Wrapper must also be an instance of PageContext. This wrapper must be returned when getJspContext() is called.
  • For each attribute declared and specified, a page-scoped variable must be created in the page scope of the JSP Context Wrapper.


  • Which doesn't mean that I agree with HFSJ's answer And it looks like it's already in the unconfirmed errata, [567] Question 18, Option F.


    [My Blog]
    All roads lead to JavaRanch
    Michael Angstadt
    Ranch Hand

    Joined: Jun 17, 2009
    Posts: 274

    Ah ok, so a tag file creates its own page-scope. In that case, it looks like the answer is correct! The book mentions "tag-scope" in a couple places, but it also says that it isn't a "real" scope...that just confused me I guess. Thanks for your help!
    Lucas Smith
    Ranch Hand

    Joined: Apr 20, 2009
    Posts: 804
        
        1

    You should use a variable directive to provide a variable into calling page scope.


    SCJP6, SCWCD5, OCE:EJBD6.
    BLOG: http://leakfromjavaheap.blogspot.com
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Page-scope vs tag-scope