Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Custom Tag inhertance.

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The tag declarations in the TLD file cannot be hierarchical. You'll just need to live with duplication if you keep them as separate tags.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic