JSP.A.1 Simple Examples


Most tags are likely to be simple encapsulations of some functionality. The first set of examples are of this type and were already introduced in Section JSP.5.1.3; here they are described in some more detail.

JSP.A.1.1 Call Functionality, No Body

The example of Section JSP.5.1.3.1 is the simplest example:

 <x:foo att1="..." att2="..." att3="..." /> 

In this case:

Tag Library Descriptor

Indicates there are 3 mandatory attributes that are only translation-time, and that FooTag is the handler for tag "foo."

FooTag

FooTag needs only to provide a method for doStartTag() . The method doStartTag performs the desired actions, possibly interacting with the PageContext data.

The attribute values are exposed as attributes and their values are set automatically by the JSP container.

JSP.A.1.2 Call Functionality, No Body, Define Object

The example of Section JSP.5.1.3.2 is a simple variation of the previous example:

 <x:bar id="mybar" att1="..." att2="..." att3="..." /> 

In this case:

Tag Library Descriptor

Indicates there are 3 mandatory attributes that are only translation-time, and that BarTag is the handler for tag "bar." For the example, assume that id is optional, in which case the TLD also indicates that as being the case.

The TLD also needs to indicate that BarExtraInfo is the name of the class that will provide information on the scripting variables introduced; see below.

BarTag

BarTag needs only provide a method for doStartTag() . The method will interact with the PageContext data to register the created object with a name that is the value of the id attribute.

The attribute values are exposed as attributes and their values are set automatically by the JSP container.

BarExtraInfo

This class, to be instantiated at translation time, needs only define a getVariableInfo() method. This method will look at the TagData object it is passed and will return either null or an array of VariableInfo objects of size 1, with the value corresponding to the scripting variable with name given by the id attribute.

JSP.A.1.3 Template Mechanisms

Section JSP.5.1.3.4 refers to a family of template mechanisms that have been used in the past. All of these mechanisms take some information and replace a token in the template page by either some fixed expansion or the result of some computation.

These mechanisms can be implemented through an empty-bodied action that is mapped to Tag handler that uses the desired information to locate the wanted resource and pushes the information into the JspWriter .

JSP.A.1.4 A 0.92-like useBean

In future releases of this specification, the useBean of 0.92 will be described. Note that the implementation will not be as efficient as ideal due to the need to do some computation at request evaluation time.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net