Java Reference
In-Depth Information
Example 18−9: DecorBox.java (continued)
// Now set default values for all the other properties
align = "center";
title = null;
titleColor = "white";
titleAlign = "left";
color = "lightblue";
borderColor = "black";
margin = "20";
borderWidth = "4";
}
/**
* This method is called when a <decor:box> tag is encountered. Any
* attributes will first be processed by calling the setter methods above.
**/
public int doStartTag() throws JspException {
try {
// Get the output stream from the PageContext object, which
// will have been passed to the setPageContext() method.
JspWriter out = pageContext.getOut();
// Output the HTML tags necessary to display the box. The <div>
// handles the alignment, and the <table> creates the border.
out.print("<div align='" + align + "'>" +
"<table bgcolor='" + borderColor + "' " +
"border='0' cellspacing='0' " +
"cellpadding='" + borderWidth + "'>");
// If there is a title, display it as a cell of the outer table
if (title != null)
out.print("<tr><td align='" + titleAlign + "'>" +
"<font face='helvetica' size='+1' " +
"color='" + titleColor + "'><b>" +
title + "</b></font></td></tr>");
// Now begin an inner table that has a different color than
// the border.
out.print("<tr><td><table bgcolor='" + color + "' " +
"border='0' cellspacing='0' " +
"cellpadding='" + margin + "'><tr><td>");
}
catch (IOException e) {
// Unlike a PrintWriter, a JspWriter can throw IOExceptions
// We have to catch them and wrap them in a JSPException
throw new JspException(e.getMessage());
}
// This return value tells the JSP class to process the body of the tag
return EVAL_BODY_INCLUDE;
}
/**
* This method is called when the closing </decor:box> tag is encountered
**/
public int doEndTag() throws JspException {
// Try to output HTML to close the <table> and <div> tags.
// Catch IOExceptions and rethrow them as JspExceptions
try {
Search WWH ::




Custom Search