Jakarta Project: PAGE JSP Tag Library

Version 1.0

Table of Contents

Overview
Requirements
Configuration
Tag Summary
Tag Reference
Examples
Javadocs
Revision History

Overview

The PAGE custom tag library contains tags which can be used to access all the information about the PageContext for a JSP page.

Tags are provided to access information in "page"-scoped attributes.

Requirements

This custom tag library requires no software other than a servlet container that supports the JavaServer Pages Specification, version 1.2.

The tag library also works in some JSP version 1.1 servlet containers, such as Tomcat, but not in others, such as Weblogic. The tags in this tag library are designed according to the JSP 1.2 specification, which makes this requirement of the <jsp:getProperty ... /> tag:

The value of the name attribute in jsp:setProperty and jsp:getProperty will refer to an object that is obtained from the pageContext object through its findAttribute() method.

The JSP 1.1 specification does not require this behaviour, and while Tomcat happens to support it, Weblogic does not. Note that it is fairly straightforward to write a custom tag that emulates this behaviour for Weblogic users. Sample source code for such a tag can be found here.

Configuration

Follow these steps to configure your web application with this tag library:

To use the tags from this library in your JSP pages, add the following directive at the top of each page:

<%@ taglib uri="http://jakarta.apache.org/taglibs/page-1.0" prefix="page" %>

where "page" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like. For the examples below the prefix "page" is used.

Tag Summary

Page Attribute Tags
attribute Get the value of a single attribute
attributes Loop through all page attributes
equalsattribute See if an attribute equals some value
existsattribute See if an attribute exists
removeattribute Remove an attribute
setattribute Set an attribute
 

Tag Reference

 attribute Availability: version 1.0 
Get the value of a single page attribute.
 
Tag Body Empty
Script Variable No
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 name  Yes  No
Name of page attribute to get.
Properties None
Example
<%-- Output the value of the page attribute with name "test1" --%>
<page:attribute name="test1"/>
 attributes Availability: version 1.0 
Loop through all page attributes.
 
Tag Body JSP
Script Variable Yes, available only within tag body.
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 id  Yes  No
Script variable id for use with standard jsp:getProperty tag, JSP version 1.2 (or equivalent, see Requirements for details)
Properties
 
Name Get Set
 name  Yes  No
Page attribute name.
 value  Yes  No
Page attribute value.
Example
<%-- Output the name and value of all the page attributes --%>
<page:attributes id="loop">
 Name: <jsp:getProperty name="loop" property="name"/>
 Value: <jsp:getProperty name="loop" property="value"/>
</page:attributes>
 equalsattribute Availability: version 1.0 
Includes the body of the tag if the page attribute equals the value of the match parameter.
 
Tag Body JSP
Script Variable No
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 name  Yes  No
Name of page attribute.
 value  No  No
If value is set to false the equalsattribute tag includes body of tag if page attribute does not equal the value of the "match" attribute.
 match  Yes  Yes
String to test for equality.
 ignorecase  No  No
If ignorecase is set to true the comparison between the attribute and the "match" attribute ignores case.
Properties None
Example
<page:equalsattribute name="test1" match="blah">
 The page attribute with name test1 matches the string "blah".
</page:equalsattribute>
<page:equalsattribute name="test1" match="blah" value="false">
 The page attribute with name test1 does not match the string "blah".
</page:equalsattribute>
 existsattribute Availability: version 1.0 
Includes the body of the tag if the page attribute exists.
 
Tag Body JSP
Script Variable No
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 name  Yes  No
Name of page attribute.
 value  No  No
If value is set to false the existsattribute tag includes body of tag if page attribute does not exist.
Properties None
Example
<page:existsattribute name="test1">
 The page attribute with name test1 exists.
</page:existsattribute>
<page:existsattribute name="test1" value="false">
 The page attribute with name test1 does not exist.
</page:existsattribute>
 removeattribute Availability: version 1.0 
Removes an attribute from a page.
 
Tag Body Empty
Script Variable No
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 name  Yes  No
Name of page attribute to remove.
Properties None
Example
<%-- Remove the page attribute with name "test1" --%>
<page:removeattribute name="test1"/>
 setattribute Availability: version 1.0 
Sets the value of the page attribute to the content of the tag body.
 
Tag Body JSP
Script Variable No
Restrictions None
Attributes  
 
Name Required Runtime Expression Evaluation
 name  Yes  No
Name of page attribute to set value for.
Properties None
Example
<%-- Set the page attribute with name "test1" --%>
<page:setattribute name="test1">Test Value</page:setattribute>

Examples

See the example application page-examples.war for examples of the usage of the tags from this custom tag library.

Java Docs

Java programmers can view the java class documentation for this tag library as javadocs.

Revision History

Review the complete revision history of this tag library.