Remember the beer webapp from Chapter 3? Let’s improve it a bit, and automate part of the HTML form:
If we make the options dynamic, they’ll be easier to update and change, without messing around with the HTML. Instead, we want the options to be generated from a Java List
created in the web application. So here’s the custom tag we want to build:
Sharpen your pencil
Your mission (if you choose to accept it) is to complete the implementation of the select
tag handler.
First, the handler class needs to implement setter methods for each tag attribute; here’s a skeleton to get you started:
Next, complete the implementation of the select
tag handler class by writing the doTag()
method. We’ve provided the method signature and a few helpful comments help you out. Don’t forget to take a look at the HTML that this tag needs to generate in OK, let’s get real....
Now you need to configure the select
tag in the TLD file. The boilerplate elements of the TLD are already provided for you. You just need to add the element to declare the select
tag, its handler class, and all its attributes.
Sharpen your pencil: Solution
Your mission (if you chose to accept it) was to complete the implementation of the select
tag handler. The handler had to implement setter methods for each tag attribute. The handler also had to implement the doTag()
method.
Sharpen your pencil: Solution
Next, you had to complete the implementation of the select
tag handler class by writing the doTag()
method. Here’s the code we used: