| Author |
tag file question
|
Steven Colley
Ranch Hand
Joined: Feb 18, 2005
Posts: 290
|
|
Hi, 1- "You can do scripting in tag file." 2- "You can�t do scripting inside the body of the tag". 1- <myTagFileExample1:frag att="Is this code valid" /> and: <%@ attribute name="att" required="true" %> Hey, <%=att%> ??? - is it valid?? 2- <myTagFileExample2:frag> <%="could it take scripting elements at this point?" %> </myTagFileExample2:frag> tagfile: <%@ tag body-content="scriptless" %> Let me do a question...<jsp oBody/> Tks
|
SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
|
 |
Charles Lyons
Author
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
|
|
I'm a bit confused as to what's what in this question: which bits are in the JSP and which are in the tag file? I think the essence of your question regards the body content of tags implemented by tag files: the answer is any tag implemented as a SimpleTag (including tag files) must not contain JSP scripting elements in their body. So for example, if the <myTagFileExample2:frag /> is a tag file (or SimpleTag) taking a body, then this is invalid: <myTagFileExample2:frag> <% scriplet %> <%= expression %> </myTagFileExample2:frag> This will cause a translation error because scripting element(s) are declared in the body. There are two explanations here: SimpleTags use a JspFragment to control the output of their body, but JspFragments (unlike BodyContent) don't push a new JspWriter onto the 'out' stack. It is therefore dangerous to use an expression inside the body of a SimpleTag/tag file because this would be written directly to 'out' and wouldn't be encapsulated in the JspFragment for later invocation. The second reason is that SimpleTag only has the doTag() method of interest, so cannot cause the container to synchronise between scoped attribues in the SimpleTag/tag file and scripting variables in the JSP page... Therefore, scripting variables are useless because they can't be updated by a Simpletag. You will note however that EL statements are valid in SimpleTag bodies, due to the different way in which they are invoked, and because they only ever reference scoped attributes/EL implicit objects, which are not as 'tied down' to the JspPage implementation as scripting variables are. Synchronisation on scoped attributes is much easier to perform from a tag file (using the JspContext/PageContext or the <c:set> JSTL action).
|
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 / Amazon Amazon UK )
|
 |
Rodrigo Alvarez
Ranch Hand
Joined: Apr 10, 2006
Posts: 75
|
|
Hi Felipe, I agree with Charles concerning the content of a the body of a tag. Concerning scripting inside a Tag File, yes, it is allowed: have a look at p500 of the HFSJ, 1rst and 2nd Q:A Cheers
|
It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
|
 |
Ernesto Leyva
Ranch Hand
Joined: Feb 23, 2006
Posts: 62
|
|
I think the number one is valid since the script expression is in the tag-file itself. The second one is invalid because the script expression is in the body of the calling tag. I believe the idea is avoid as much as possible scriptlets so in your first code you can use <myTagFileExample1:frag att="Is this code valid" /> and: <%@ attribute name="att" required="true" %> Hey, ${att} and should work the same. The body content of a tag-file by default is scriptless. You do not need the directive in your second snippet.
|
 |
 |
|
|
subject: tag file question
|
|
|