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.