• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valid return EVAL_BODY_INCLUDE??

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given this tag handler class excerpt:
11. public class WorthlessTag extends TagSupport {
12. private String x;
13. public void setX(String x) { this.x = x; }
14. public int doStartTag() throws JspException {
15. try { pageContext.getOut().print(x); }
16. catch (IOException e) { }
17. if (“x”.equals(x))
18. return SKIP_BODY;
19. else
20. return EVAL_BODY_INCLUDE;
21. }
22. public int doEndTag() throws JspException {
23. try { pageContext.getOut().print(“E”); }
24. catch (IOException e) { }
25. if (“y”.equals(x))
26. return SKIP_PAGE;
27. else
28. return EVAL_PAGE;
29. }
30. }
and given this TLD excerpt:
21. <tag>
22. <name>worthless</name>
23. <tag-class>com.mycom.WorthlessTag</tag-class>
24. <body-content>empty</body-content>
25. <attribute>
26. <name>x</name>
27. <required>true</required>
28. <rtexprvalue>true</rtexprvalue>
29. </attribute>
30. </tag>
(continued on next page.)
12
appendix A final mock exam
you are here􀀗
and given this complete JSP page:
1. <%@ taglib uri=”somevaliduri” prefix=”w” %>
2. <w:worthless x=”x” />
3. <w:worthless x=”<%=Boolean.TRUE.toString()%>” />
4. <w:worthless x=”y” />
5. <w:worthless x=”z” />
What output does the JSP generate?
A. xE
B. x trueE yE
C. xE trueE yE
D. xE trueE yE zE
E. x <%=Boolean.TRUE.toString()%>E yE
F. xE <%=Boolean.TRUE.toString()%>E yE
G. xE <%=Boolean.TRUE.toString()%>E yE zE


The correct answer is C. My doubt is in the above question :-
we declared the <body-content>empty</body-content> for the taghandler. In that case doStartTag() are not allowed to return EVAL_BODY_INCLUDE.
If we exlicitly specify that this tag handler dosen't allow to have body, then while returning EVAL_BODY_INCLUDE , which is not a valid one in this case, this class should throw an exception.???

Please correct me!!

Thanks
 
Sourin K. Sen
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is what the JSP spec has to say :

If the TagLibraryDescriptor file indicates that the action must always have an
empty element body, by a <body-content> entry of “empty”, then the doStart-
Tag() method must return SKIP_BODY


But no where in the JSP spec is it mentioned that if the value of <body-content> is empty and doStartTag() returns EVAL_BODY_INCLUDE, then an exception will occur. However, we can deduce the same with the "must" keyword used in the above line.

But still it sure is confusing. Can anyone help us out in this regards??
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a <body-content> entry of “empty”, then the doStart-
Tag() method must return SKIP_BODY


I guess it itself shows that doStartTag dosen't allow to return anything else SKIP_BODY.

Ranchers, Please provides your inputs !!
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,

Can anyone help us out in this regards??
 
Gupta Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct. If there is no body, then the container will only return SKIP_BODY.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic