This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

TagSupport

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HF Page 766 Ques 12 Final Mock Exam

Ques12

Given this tag handler

package com;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;

public class WorthLessTag extends TagSupport {

private String x;
public void setX(String x) { this.x = x; }
public int doStartTag() throws JspException {
try {
pageContext.getOut().print(x);
}
catch (IOException e) {}
if("x".equals(x))
return SKIP_BODY;
else
return EVAL_BODY_INCLUDE;

}

public int doEndTag() throws JspException {
try {
pageContext.getOut().print("E");
}
catch (IOException e) {}

if("y".equals(x))
return SKIP_PAGE;
else
return EVAL_PAGE;

}
}


and given this TLD
<tag>
<name>worthless</name>
<tag-class>com.WorthLessTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>x</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>


The tld clearly mentions that body-content should be empty but the doStartTag returns EVAL_BODY_INCLUDE.
Why doesn't this give an error ?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... because it's allowed. Just like you can have tags that support JSP content, but tell your app that no JSPs can have JSP content without suddenly making everything not compile ... you can do the same thing here in your example. Basically, think of the tag as the object, and the TLD as the context for the tag -- two separate things.
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic