Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attributes in Tag Files: 'Tag' scope or Page scope?

 
Ted Young
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making my way through the Head First Servlets and JSP book and I've come across something which has got me confused.

In the mock exam for Chapter 10, Custom Tag Development, Page 567, option F for Q. 18 says that "for every attribute declared and specified in a Tag File, the container creates a page-scoped attribute with the same name."

But on Page 494, the 'Bang' alert box says "All tag attributes have tag scope"

The two statements seem to contradict each other. So which is right? Or am I missing something here?
[ September 20, 2007: Message edited by: Gnidocta Doogon ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not have the book handy, but are they talking about tag files in one case and custom tags in the other?
 
Ted Young
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
I do not have the book handy, but are they talking about tag files in one case and custom tags in the other?


No, actually. The alert I mentioned was in the section for tag files.

So, which is right, in any case? Attributes declared with an <%@ attribute %> directive would be in the tag's scopre only, right? Somewhat like a code block's local variable?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is correct. When I get home I will check to see if you got a good answer. If not, then I will check what the book says and see if I can answer your question.
 
Ted Young
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
I think that is correct. When I get home I will check to see if you got a good answer. If not, then I will check what the book says and see if I can answer your question.


Thank you
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the key phrase is "attribute declared and specified in a Tag File.

The Bang Box on 494 shows that the attribute in the tag (which is on a page that is not the tag file itself) cannot be used anywhere on the page that is using the tag. The tag file itself is a different matter. In it the attribute that was declared can be used anywhere in this tag file.

When you are in the page that is using the Tag File, you can only assign a value to the attribute that was declared in the Tag File itself. This value can and probably will be used in the Tag File itself

So you have a page that is using a Tag File. The page using the Tag File will assign a value to the attribute that was declared in the Tag File itself. The Tag File will use this value.

Make any sense?
 
Ted Young
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I think I get it now. This is what I figure:

A Tag File is in essence a JSP that is used sorta like an include. So the attribute is in the Page scope of the Tag File ( since it is a JSP in the end ) but that attribute doesn't overflow into the scope of the JSP that is actually using the tag.

Thanks a lot, that cleared it up for me!
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you got it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic