Tag Attributes Are Tag Object Properties

This section describes custom tag attributes, which are defined as tag object properties with setter methods.

The JSP tag extension facility maps each attribute encountered in a custom tag to a property of the same name in the tag object. So if you want to use an attribute in a custom tag, you must define a property in the tag class with the same name as the attribute. Here are the steps you need to follow to add an attribute to a custom tag:

1. Define a property in the tag class with the same name as the attribute name by adding a setter method and a getter method. This is the same way as defining a property in a JavaBean class.

2. Add an "attribute" element inside the "tag" element in your TLD file with the following syntax:

<tag>
 <name>tag_name</name>
 <tag-class>class_full_name</tag-class>
 <body-content>empty | jsp</body-content>
 <attribute>
  <name>attribute_name</name>
  <required>true | false</required>
 </attribute>
</tag>

3. Add the attribute to the custom tag in your JSP page. Then the tag is processed, the setter method of the tag object will be called to pass the attribute value into the tag object.

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

Custom Tag Attributes

Tag Attributes Are Tag Object Properties

 Setter Method Example - EchoTag.java

 Value Type Conversion

 Value Type Conversion Example - AttValueTag.java

 Accepting EL Expressions

 Accepting EL Expression Example

 Passing Expression as String Example

 Using jsp:attribute Action Elements

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version