Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Custom Tag inhertance.

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic