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.
Is there a completely different approach for my problem. (Both tags do excatly same things, but a slight change, So i used inheritance)
If both tags do exactly the same thing, I would only use one tag.
It sounds like your TagHandler has a lot of code logic in it, because usually you would only override doTag() or init().
So, i would suggest to encapsulate all the other business methods away into separate Helper classes, and then - since there is only a slight difference between A and B, determine in your tag handler how to process the tag.
JDBCSupport - An easy to use, light-weight JDBC framework -
If both tags do exactly the same thing, I would only use one tag. --> They do almost the same thing, the place where they differ hence i have two tagHandlers A, B.
A extends SimpleTagSupport.
B extends A
overrides the methods, the makes sense for B.
With this inheritance, lot of duplication is hidden.
My question was in the .tld file there are two definitions for A, B.
A has 3 attributes.
B has 4 attributes. only one extra that differs.
There is this duplication of attribute definition.
Cant we declare B, like all the attributes of A and then my extra attribute.