• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

benefit of taglibs

 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks & sheriffs,

that's a serious question: what are the benefits of taglibs?

i just see disadvantages. to name a few, unordered:

- loosing type-safety
- almost impossible to refactor automatically
- new syntax to learn
- runtime-evaluation
- often: need of injecting EL, which is just another syntax to learn, and another runtime-evaluated language
- hard if not impossible to debug (it's almost always try-and-error)
- loose of control over generated html-code (formating, xhtml, ...)

i would be really gracefull if anybody could enlighten me why we are all using it. :-/

btw: yes, i prefer scriptlets:
- type safe
- compile-time evaluated
- debugable
- refactorable
- readable
- nothing new to learn

many thanks,
jan
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me say this as a Rule of Thumb:

JSP taglibs - Hard to create but easy to maintain and debug.

scriptlets - Easy to write, but hard to maintain and debug.


suppose think about this scenario,

1. If you have same logic for different JSP.
In this scenario, If you use scriplets, you need to duplicate the code in both JSP. But in taglib you can add it to tag class and reuse it.

2. Suppose now you want to replace the logic with new one for above scenario, now you need to change both JSP, but in taglib you need to change only in tag class. All others will change to use new code.

hth,
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your answer, but I'm not so convinced.


JSP taglibs - Hard to create but easy to maintain and debug.
scriptlets - Easy to write, but hard to maintain and debug.



sorry, if you re-read my post, i definitely think that the opposite is true.

did you ever set a break-point in a jsp-tag? (it's not possible)
did you ever rename a form property? (the tag has not been refactored)
same goes for type-safety, runtime vs. compile time evalutation and so on...


If you have same logic for different JSP.



we have a MVC-pattern, and dont want logic in jsps. i dont think that you need anything more than some if / else and loops. that's all, for sure. so reusablity of jsp source code is not an issues for me. i can use tiles / includes to reuse jsp-fragments.

But in taglib you can add it to tag class and reuse it.



well, i can add scriplet code to controller classes as well. and reuse ;-) . and i was not so much refering to writing taglibs, more to using it. and i will not add my logic to jstl-common library ;-)

still frustrated,
jan
[ November 17, 2006: Message edited by: Jan Groth ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jan Groth:
thanks for your answer, but I'm not so convinced.



Just look at the track record for the two.
Scriptlet heavy apps have been a nightmare to maintain.
The point of taglibs is to get the heavy coding out of the view tier.

This thread belongs in the JSP forum so, moving...
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see your point with some of the disadvantages particularly the ones about typesafety, and refactoring.
Thats one of my minor gripes about EL is because it uses reflection, it isn't evaluated until runtime. And if you spell the field wrong, it will just quietly return null rather than throwing an error. That can lead to some subtle errors in the page.

With regards to the learning curve, I don't think its that bad.
A for loop is a for loop. An if is an if. The basics are the same anywhere. So its in HTML syntax rather than java. The JSTL tags at least are mostly logical and consistent.

Control over generated HTML code. I see your point a little.
But the same is true in any JSP with its carriage returns everywhere.
IMO:
The end user is not going to be worried about the html source. Just whether the page looks good or not.
I think I would trust most tags to generate HTML more correctly than I could.
- escaping bad characters (<c:out>, <c:url>/<c:param> tags)
- generating correct HTML tags. Opening/closing them all correctly. Putting quotes on all attributes properly. The tags are enforced whereas template HTML is not. (depending on the tool)
Yes you lose some control over the generated HTML, but to my mind the gains are worth it.


Your "benefits" of scriptlet code in the JSP.
> compile-time evaluated.
True, but often a JSP won't be compiled until it is run. Just as bad IMO.
I prefer to write Java code into a java class - where I get instant compile feedback.

> debuggable : If you have the source code for the tag, you can "debug" into it. If its a well written tag though, you normally won't have to.
I will admit I haven't tried actively debugging a JSP often. But thats normally because it is so simple I don't need to step though.

>readable: Personally I find JSTL tags a lot more readable than scriptlet code.

The debugging/refactoring/typesafety is mainly an IDE thing to me.
The tool enables you to be able to do these things in a JSP. Not so long ago you didn't have those tools in JSP scriptlet code. It was basically a text editor - you had to run the page to get it to compile.


The advantages of the taglibraries as I see it
- consistent syntax. Tags are tags are tags. All you see in my JSP page now is tags and template text. No java scriptlet code embedded among it. Makes it much more readable as there is only one "language" being used.
- it is easier to match open/close tags in a JSP then it is to match those curly brackets like <% } %>

- Learning curve. If you know java, then naturally you find scriptlet code easier. If you only know HTML then the taglibs will probably be easier to learn, without java syntax. Not that it matters that much.

I agree that JSTL/EL is not perfect.
But I find it a big improvement over scriptlet code.
It IS possible to write good pages in scriptlet code. It is also very easy to abuse scriptlet code and make a page unmaintainable.
Using tags like JSTL make it less easy to abuse things on the page.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
helle stefan,

thanks for taking the time to answer...

guess it's like it is, and i cannot change the world ;-)

coming from a cms-background, i usually had a cms-framework, which provided all the text (=data to display) in a bean-less scriplet way (...content.getHeadline()...). so i kind of "grew up" with all the benefits of scriplets (pointed out above).

.. and had a hard switch to this runtime-&/'!"/&$�!-nightmare.

anyhow,
thanks again,
jan
 
I like tacos! And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic