Accessing Tag Attributes

Just like regular tags, custom tags can have attribute values. You just need to provide get and set methods for each attribute. Although you enclose each attribute in quotes, you can have numeric attributes in your custom tag. The JSP engine performs the conversion automatically. Listing 16.24 shows a custom tag to display a checkerboard. The board has several options that can be changed by various attributes in the <xx:checkerboard> tag.

Code Listing 16.24. Source Code for CheckerboardTag.java
 import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.*; import java.io.*; public class CheckerboardTag extends TagSupport { // Variables to hold the attributes for the checkerboard protected int width = 40; protected int ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.