Saturday, July 17, 2010

Why is the use of JSTL a good practice?

I've been doing software development for a long time. I've worked with new technologies, new practices and approaches at solving problems using the technologies at hand. One of the things I've learned is to follow good practices and work towards simplicity. And simplicity is what I don't see when using things like JSTL or other custom tag libraries from various product vendors.

I've been working with Java for a long time now, and when JSP's first came into picture it was a nice thing to be able to include Java code to control the rendering of the HTML output. It was a simple template mechanism without much complexity other than mix HTML and Java. Later some people thought adding tag libraries was a better approach, the reasoning behind it, I believe, was mainly that embedding Java into HTML pages is not elegant and makes the source of HTML pages hard to read by the HTML designers and the programs used to design them. This, to me, is not a good reason to make custom tag libraries or JSTL needed. In most cases, once the HTML page is designed is then given to a Java developer to convert it into a JSP. The converted source will never go to the original HTML designer. The JSP version of the original HTML page is no longer useful to the designer, unless He is viewing it from the actual application server. So let's face it , the JSP will almost never go to the hands of the HTML designer for changes, it will always be the Java developer the one making the changes.
Another reason, for not needing to add to the confusion and complexity of the JSPs by using JSTL, is that you can not do everything using just tag libraries. You will most likely need to embed some Java scriptlets, making the source more complex to understand (HTML + JSTL + Custom Tags + Java scriptlets), so why not just use Java scriptlets as the way to control the output generation. This way we do not have to be learning new tag libraries, we do not need to figure out what we can and can not do with these libraries. Combining HTML and Java scriptlets only makes our job much easier.

No comments: