• Post Reply Bookmark Topic Watch Topic
  • New Topic

taglib vs. JSP 2.0 tagfile

 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been doing some learning lately about tag libraries and I'm reading some stuff now on "tagfiles" which are apparently new in 2.0.

Are they superior...should I be using them in the place of custom tag libraries? What are the basic limitations in any of your experiences?

It would appear that they are a matter of mixing scriptlet code into a JSP...exactly what you would *not* want to be doing in a regular JSP. Is this the case?

Thanks!

-v
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I kinda like the tagfile facility provided in JSP 2.0. To me, they provide a simple yet efficient way to reuse UI element because of the textual representation, rather than compiled custom tag.

I would say that tagfile are superior than custom taglib in term of their ability to manipulate textual contents naturally. Drawing a loose analogy, a tagfile to custom taglib is just like a jsp file to a servlet.

However, if you don't want page developer or web designer to access your tag logic, put them in custom tag rather than tagfile.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are complimentary, not competing technologies. Tag files are most useful when your tag focuses mainly on markup. In this way, you avoid having to build up markup in text strings and then emit them. Java-based tags are still a good choice for less markup-intensive uses. I use both types on a regular basis.

Tag files, btw, are implemented by the container by turning them into "regular" Java-based tags behind the scenes.

t would appear that they are a matter of mixing scriptlet code into a JSP...exactly what you would *not* want to be doing in a regular JSP. Is this the case?


Absolutely not. In fact, you cannot use scriplets or scriplet expressions in a tag file.
[ October 16, 2005: Message edited by: Bear Bibeault ]
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, very helpful. Bear, you make an excellent point. If I were to implement markup in my tags - tagfiles are obviously the way to go to avoid a pile of pasta w/ print statements in a custom tag.

So far as I can tell, tagfiles can do anything a custom taglib can do...but easier (for UI elements.)

Now, if only I could get one to work...but that's for another thread.

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far as I can tell, tagfiles can do anything a custom taglib can do


Since you cannot use scriplets within a tag file, any computation or heavy data structure manipulation can be problematic. For this, class-based tags still reign.

On the other hand, a hybrid approach is possible by using tag-file-specific helper beans to offload the heavy lifting -- hmmm, that might be a good topic for a future JavaRanch Journal article...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!