|
<taglib:tutorial lesson="12"> In this lesson, we will take a closer look at the Tag Library descriptor changes between JSP 1.1 and JSP 1.2.
Lesson 12, Changes to the TLD
The new variable tag The modified attribute tag The name changes The new validator tag The new listener tag 1 Lesson 12, Changes to the TLD In this lesson, we will take a closer look at the interesting parts of the Tag Library descriptor changes between JSP 1.1 and JSP 1.2. We will not write any code in this lesson, but instead use parts of the Tag descriptor from lesson 10, lesson 11 and lesson 12 as an example. You should therefore have finished lesson 10 before continuing on this one. 2 The new variable tag
Back in JSP 1.1, one would have to describe any variables that were to be added through a VariableInfo class held by a TEI implemented for this particular Tag (this is covered in greater detail in lesson 5). This unfortunate implementation style led to that a lot of new deveopers gave up on writing custom Tags as they found it too troublesome. Therefore, the expert group of JSP 1.2 added the ability to define simple VariableInfo implementations directly in the TLD, which can look like in listing 1 below:.
Take a good look at the <variable> part above, and then compare it to the VariableInfo class below:
The observant reader will notice that the <variable> tag added in JSP 1.2 holds the data of the old VariableInfo class that was added in JSP 1.1 and some new items. Let's have a look at the tags involved: This might look like a minor addition, but it has a major impact on development time. Refer to lesson 17 to get an example usage of the new 3 The modified attribute tag The attriute tag has been modified in JSP 1.2 so that the Tag developer can now tell the container what type to expect for a certain attribute, thereby sparing the Container from guessing. This might look as in the example below:
4 The name changes The JSP 1.2 Tag library descriptor has changed the name of most old tags to better comply with the other J2EE descriptor files. Most of these changes boils down to separating words with a dash. For instance, the tag named "tagclass" in JSP 1.1 is now known as "tag-class". 5 The new validator tag Back in JSP 1.1, Tag developers could put translation-time validation into the isValid() method of a TEI class (see lesson 5), and that method could use the information held by the TagData given to it to validate the tag usage. The JSP 1.2 Tag library descriptor now allows for a TagLibraryValidator class to be specified for a Tag library, so that this validator is invoked as soon as a page is compiled that utilizes the Tag Library that the validator is part of. The TagLibraryValidator is described within a <validator> tag, as exemplified in listing 3 below:
When a JSP page that utilizes a Tag Library containing a TagLibraryValidator is compiled, the Container will execute the validate() method of the specified validator. As this is covered in lesson 14, we wont go into any details here. The <validator-class> tag contains the fully qualified name of the TagLibraryValidator implementation. The <init-param> tag can be used to specify any number of parameters that should be passed to the validator during initialization. The <description> tag is used to enter a optional description of the TagLibraryValidator class. 6 The new listener tag The JSP 1.2 Tag library descriptor can hold an event listener that will be instantiated and registered automatically. Web application listener beans was introduced in Servlet 2.2 (at that time one could include HttpSessionBindingListener implementations in Web-modules) and was further extended in Servlet 2.3 with the additions of ServletContextAttributeListener, ServletContextListener, HttpSessionActivationListener and HttpSessionAttributeListener. The event listener implementation is described within the <listener> tag as exemplified below:
Listeners will be covered in lesson 13, "Using Listeners", which happends to be the next lesson. Copyright © 2005 IronFlare AB |