I was reading in the JSP 2.0 Specification that when creating a tag-file the container will create a copy of the JspContext called "JspContextWrapper". it says "must present a clean page scope". What I understand is that all page-attributes added before invoking the tag-file will not make it in the JspContextWrapper and that those attibutes added to the JspContextWrapper would be valid in the tag-file only. Can someone confirm this?
Supporse I have a tag-file called "myTagFile.tag" like this
What I understand is that all page-attributes added before invoking the tag-file will not make it in the JspContextWrapper and that those attibutes added to the JspContextWrapper would be valid in the tag-file only. Can someone confirm this?
That's correct - all page-scoped attributes in the calling JSP are isolated from all page-scoped attributes in the tag file.
The output would be:
My Attribute in calling JSP is AAAA My Attribute in Tag-File is null My Bean name in Tag-File is BBBB My Bean name in calling JSP is null
This is the output I would expect.
Also Would this JspContextWrapper apply to SimpleTags and classic tags too?
No. The short answer is that this is only mandated in the Tag Files section of the specification. The longer explanation is that tag files need to have their 'own scope' because of things like attributes - all attribute values are placed in the Context Wrapper's page-scope when the tag is invoked, and so to avoid conflicts with page-scoped attributes in the page, the wrapper is essential. This is distinct from a normal tag handler implementation (either classic or SimpleTag) because here you implement JavaBean setter methods to set attributes, so no 'special page-scope' is required. The next question you'll ask is how to actually export a variable from the tag file, for instance in your previous example, how could we actually get "My Bean" to be the value of the bean in the calling JSP page? The answer is synchronisation, confusingly a different kind to that using in regular classic handlers, but all explained in my book (even though it isn't on the exam)! [ April 19, 2006: Message edited by: Charles Lyons ]
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )