• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practice for writing custom tags

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've wrote a couple of custom tags for my web app and I've noticed the more I add to the code the messier it becomes, jspWriter commands and escaped HTML tags as strings just look messy, does anyone know of a best practices guides to writing custom tags or have any tips to keep the code behind them readable? I wanna get it right from the start rarther than revisiting the code later on en doing a hell of alot of refactoring.

example of what I'm talking about


Steve
 
Sheriff
Posts: 67747
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
A custom tag that emits lots of markup is best implemented as a tag file rather than as a Java class.
 
Stephen Foster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a really good idea and would definitely make my HTML code more readable although I would lose the advantages of having a Java class behind my code. I will examine the code I've written and see if I can replace my custom tag with a tag file.

Its a shame that there isn't a way that combines the advantages of tag files and custom tags...

Thanks for your help Bear
 
Bear Bibeault
Sheriff
Posts: 67747
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
When I implement a tag file that would benefit from some Java processing, I've created a "helper bean" that the tag can employ to do some heavy lifting for it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic