This doAfterBody method was correct, but it runs only AFTER the body has already been processed once!. -Option C is invalid because an attribute in page scope would be found before check
Trang 1But where do you loop over the body, if the body is evaluated in between the methods instead of IN a method like doT
ag()?
ItÕs easy to loop the body of a Simple tag;
you just keep calling invoke() on the body, from within doTag().
LWHUDWLQJZLWK&ODVVLFWDJV"
Trang 2:HE&RQWDLQHU &ODVVLFWDJFODVV 7DJ+DQGOHU2EMHFW
These happen the Þ rst time the tag is inv oked, but the Container may (dep ending on the circumstances) r euse the Classic tag object after this.
This gives the handler a reference to a PageContext.
If the tag is invoked with attributes, the JavaBean-style setter for each attribute is called (just as with SimpleTag handlers).
A nested tag can communica te with the other tags in which i ts nested.
doAfterBody() lets you do things AFTER the body runs, and unlike the other methods it can be inv oked more than once.
The body is evaluated between the doStartTag() and doEndTag() methods.
Trang 3&ODVVLFWDJOLIHF\FOH
Trang 4public int doStartTag() throws JspException {
public int doAfterBody() throws JspException {
public int doEndTag() throws JspException {
}
Trang 5'HVLUHGUHVXOW-63WKDWLQYRNHVWKHWDJ
#WDJOLESUH¿[ ´PLQH´XUL ´.DWK\&ODVVLF7DJV´!
Trang 6HYDOXDWHG
Trang 7$PHOLH
ThereÕs an empty cell at the top!
You MUST add these t wo lines
to produce the corr ect response
This doAfterBody() method was correct, but it runs only AFTER the body has already been processed once! Without the two extra lines in doStartTag(), the body is proc essed once without there being a movie attribute, so you get the empty c
ell.
&ODVVLFWDJH[HUFLVHDQVZHUV
Trang 8YOUHAS9ES 3IMPLE4AGCOURSEYOUDTAGYOUDDO3TART4AG
ITS
THE FOR DO3TART4AG
JUST
HANDLERS
#LASSICANDMEANSINSTANCENEWDO3TART4AG WORKSAVARIABLEINSTEAD
Trang 11IURPGR6WDUW7DJ LI\RXU7/'GHFODUHVDQHPSW\ERG\IRUWKHWDJHYHQ,)
Trang 13SKIP_BODY EVAL_BODY_AGAIN
SKIP_PAGE EVAL_PAGE
SKIP_BODY EVAL_BODY_INCLUDE
Exactly once, and ONLY if doStartTag() returns EVAL_BODY_BUFFERED
Trang 14LQWHUIDFH!!
7DJ
Trang 15LQWHUIDFH!!
7DJ
YRLGGR7DJ -VS7DJJHW3DUHQW YRLGVHW-VS%RG\-VS)UDJPHQW YRLGVHW-VS&RQWH[W-VS&RQWH[W YRLGVHW3DUHQW-VS7DJSDUHQW
Again, donÕt forget the cas t.
ItÕs exactly the same as
in a Classic tag handler.
PLQH2XWHU7DJ!
PLQH,QQHU7DJ!
PLQH2XWHU7DJ!
$QHVWHGWDJFDQDFFHVVLWVSDUHQWHQFORVLQJ WDJ
In this relationship, ÒOuterTagÓ
is the parent of ÒInnerTagÓ.
WKHJHW3DUHQW ...
.H\OLIHF\FOHPHWKRGVWKDW
< 28 PLJKWLPSOHPHQW
doEndTag() doAfterBody() (and for BodyTagÑ doInitBody() and setBodyContent())
+RZ\RXZULWHWRWKHUHVSRQVH... invalid because the jsp: body action can appear in EITHER a tag Þle or JSP.
-Option F is invalid because the taglib directive can appear in EITHER a tag Þle or JSP.
-...
-Option A is invalid because Simple tags have a getParent method.
(JSP v2.0 SimpleTagSupport API pg 2 -86 JSP v2.0 TagSupport API pg 2-64)
-Option B is invalid because