|
<taglib:tutorial lesson="2"> In this part of the tutorial, we will create a Tag that accepts and displays a parameter.
Lesson 2, Your first parameterised Tag
Creating the Hello Tag Writing the descriptor Creating a presentation Using your new Tag 1 Lesson 2, Your first parameterised Tag
In this part of the tutorial, we will create a Tag that accepts and displays a parameter. We will continue to use the setup previously defined. As you might have noticed in lesson 1, even a simple Tag requires us to write a number of methods that we will be using over and over again. The natural thing to do would be to make a generic Tag that we can extend throughout this tutorial. But surprise! Sun has already done so for us. In the javax.servlet.jsp.tagext package, there is a class called TagSupport that looks like in figure 1 below:
Apart from the methods that is required by the Tag interface, the TagSupport class holds some utility methods that we can take advantage of. Amongst these are: We will now leave the TagSupport to get on with the tutorial. If you want to learn more or get a deeper understanding about the TagSupport, read the JSP API or the JSP 1.1 Specification. 2 Creating the Hello Tag
We will now create a Tag called 'HelloTag' that extends the TagSupport class as shown in Figure 2 below.
3 Writing the descriptor
With the new Tag in place, we should add a descriptor of our new Tag to the Tags descriptor we created in the first lesson. This will tell our JSP container that the new tag can accept an attribute called Name and that the Tags body should be empty. The <rtexprvalue> that is set to false will tell the Container that the name attribute will not be evaluated at runtime (i.e. can not be a dynamic value). ![]()
4 Creating a presentation
In order to test our new Tag, we need to write a JSP page that uses it. ![]()
5 Using your new Tag Its now time to test your new tag. ![]()
Continue with lesson 3, "Writing a BodyTag". Copyright © 2005 IronFlare AB |