Implicit Tag Libraries require (and finally have!) a JSP Version Number

Implicit Tag Libraries require (and finally have!) a JSP Version Number

Implicit Tag Libraries require (and finally have!) a JSP Version Number

This blog describes a deficiency related to the JSP versioning of Implicit Tag Library Descriptor (TLD) files introduced in JSP 2.0, and how JSP 2.1, now in Proposed Final Draft 2 and implemented in Glassfish build 37, has decided to address it.

Background

One of the goals of JSP 2.0 has been to simplify JSP development. To address this goal, JSP 2.0 introduced the tag file facility, which allows page authors to create tag libraries using JSP syntax. This means that page authors no longer need to know Java to write a tag extension.

Tag files may be referenced from a TLD just as any tag handler implemented in Java, by using the <tag-file> element.

JSP 2.0 went one step further and also eliminated the need for creating TLD files for tag libraries that consisted exclusively of tag files. In order to take advantage of this feature, tag files must be placed in a web application's /WEB-INF/tags directory, or a subdirectory of it. The JSP container interprets the /WEB-INF/tags directory, and each subdirectory under it, as another implicitly defined tag library containing tag handlers defined by the tag files that appear in that directory. For example, the following web application contains 3 implicit tag libraries:

  /WEB-INF/tags/
  /WEB-INF/tags/a.tag
  /WEB-INF/tags/b.tag
  /WEB-INF/tags/foo/
  /WEB-INF/tags/foo/c.tagx
  /WEB-INF/tags/bar/barr/
  /WEB-INF/tags/bar/barr/d.tag

Problem

Tag libraries must specify the version of the JSP specification that they depends on. TLDs that depend on JSP 1.2 or earlier specification versions must specifiy the JSP version in their <jsp-version> element. Starting from JSP 2.0, the JSP version must be specified as the value of the mandatory "version" attribute of the <taglib> root element.

The JSP 2.0 specification did not specify how the JSP version of an implicit TLD was derived, and most containers (including Glassfish) have hard-coded the JSP version of an implicit TLD at "2.0".

The Unified Expression Language (EL), which has been one of the most important feature additions to JSP 2.1, introduces the concept of deferred expressions, which are indicated by the #{expr} syntax. In order to remain backwards compatible with JSP 2.0, which has no notion of deferred expressions, the JSP 2.1 specification requires that when used as a tag attribute value inside a tag invocation, the #{expr} syntax must be evaluated by the container only if the JSP version of the tag handler's underlying TLD has a value of "2.1" or higher. See Kin-Man's blog for more information about the Unified EL, and how backwards compatibility was temporarily broken in one of the earlier Glassfish builds.

Since it is impossible to configure the JSP version of an implicit TLD, and since most containers have hard-coded the JSP version of an implicit TLD to be "2.0", the concept of deferred expressions introduced in JSP 2.1 cannot be applied to invocations of tag handlers supported by tag files referenced by an implicit TLD: a very severe limitation, especially in light of all the attention that tag files have attracted since JSP 2.0!

Solution

In order to address the above shortcoming, JSP 2.1 PFD2 allows certain aspects of an implicit TLD, such as its JSP version number, to be configured by placing a TLD file with the reserved name implicit.tld into the same directory as the implicit tag library's constituent tag files:
  /WEB-INF/tags/
  /WEB-INF/tags/a.tag
  /WEB-INF/tags/b.tag
  /WEB-INF/tags/foo/
  /WEB-INF/tags/foo/c.tagx
  /WEB-INF/tags/bar/barr/
  /WEB-INF/tags/bar/barr/d.tag
  /WEB-INF/tags/bar/barr/implicit.tld

The JSP version specified in an implicit.tld file is used to set the JSP version of an implicit TLD. JSP 2.1 PFD2 has also clarified that the JSP version of an implicit TLD defaults to "2.0".

Example: In order to set the JSP version of an implicit TLD to "2.1", the following implicit.tld could be used:


  <taglib
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    version="2.1">
      <tlib-version>1.0</tlib-version>
  </taglib>

Support for the implicit.tld feature is available in the latest Glassfish build 37 build. Go try it out and let me know if you have any questions!

Comments:

游戏查找

Posted by 魔兽私服 on July 19, 2007 at 02:56 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

jluehe

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today