InvoiceCondition.java
package allaire.samples.invoice.taglib;
import java.io.IOException;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class InvoiceCondition extends BodyTagSupport {
public int doStartTag() throws JspTagException {
InvoiceIf parent = (InvoiceIf)
findAncestorWithClass( this, InvoiceIf.class );
if ( parent == null ) {
String message =
"The condition tag must be inside an if tag.";
throw new JspTagException( message );
}
return EVAL_BODY_TAG;
}
public int doAfterBody() {
InvoiceIf parent = (InvoiceIf)
findAncestorWithClass( this, InvoiceIf.class );
String bodyString = getBodyContent().getString();
if ( bodyString.trim().equals( "true" ) ) {
parent.setCondition( true );
} else {
parent.setCondition( false );
}
return SKIP_BODY;
}
}