Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Best practice for writing custom tags  RSS feed

 
Stephen Foster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!