tags:

views:

42

answers:

1

Hello, I have a JSP custom tag "A" defined in my .tld. It has 3 required attributes. It has its ATagHAndler that inherits SimpleTagHandler. I need a new tag "B" that does excatly the same thing as the above "A" but in a little different way. Also the attributes that are present in "A", i copied them to "B" in the .tld file (Code duplication)). Further the I created a BTagHandler extends ATagHandler, and overrided the few methods that actually changes across these two handlers.and rest functionality is defined in "ATagHandler. On java side its cool, cause lot of code duplication is avoided due to inheritance.

But in the .tld file that has the defination of Tag A and TAg B, there are duplication of the attributes definition. Is there a way to avoid this duplication. If not, Is there a completely different approach for my problem. (Both tags do excatly same things, but a slight change, So i used inheritance)

Regards, Deepak

+1  A: 

I think you're going to have to live with the TLD duplication, I know of no way to do what you want to do. It is annoying, and it doesn't feel right, but TLD files are crude and ugly.

You have the option, though, of implementing the javax.servlet.jsp.tagext.DynamicAttributes interface. This allows you to omit the attribute declarations from the TLD, so you don't have to repeat them, but the downside is that the attribute values will be passed to your tag as name-value pair rather than as a javabean property, so they're not as nice to use.

So it's a choice between unpleasantness in the TLD, or unpleasantness in the Java. Take your pick.

skaffman
+1. As far as DynamicAttributes interface goes, the biggest problem with it is lack of compile-time checking. With TLDs (crude as they are) compilation will fail if you misspell an attribute; with dynamic attributes you at best will get a runtime JspException and at worst wrong attribute will just be silently swallowed leading to indeterminate behavior.
ChssPly76