O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

I’m getting sick of these tag attributes!

image with no caption
image with no caption

You’re right. This solution sucks. And it’s tons of code to keep up with. Worse, what if we want to create a suite of custom tags to augment other HTML tags?!

The tag handler class must implement a setter method for each of the tag attributes declared in the TLD. But these setter methods aren’t really doing anything interesting. The values of these attributes are simply passed on to the output generated for the HTML <select> tag.

We could apply an design principle: “Encapsulate that which varies.”[9] In this case the set of optional HTML tag attributes is the thing that varies in this tag handler. One solution would be to put all of the attributes into a hashtable. This generalizes the tag object’s storage of attributes, but what about all these setter methods? We can’t get rid of them unless there’s a way to tell the JSP engine to set the tag attributes using a generic interface.

image with no caption
image with no caption

Relax

You will not be tested on the method signature and definitely not on the purpose of the uri parameter.

Hell, we don’t even know what it’s for.

[9] This design principle ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required