• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TagSupport

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic