JSTL Gripe

Now I am using JSTL in my JSP pages I have found something really annoying.

JSTL provides a very handy mechanism for calling properties on beans.

If you have a bean called "bob" and a bob has a method called "getFoo", then you just put <c:out value='{$bob.foo}'/> in your page and you get the result of calling getFoo on bob.

Initially, this seems very useful.

However, the Javadoc for the Method you call to put bob into the request for accessing in the page says the following:

Attribute names should follow the same conventions as package names.

Names beginning with java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems.


So, the suggestion is that when you put a bean in the request you use the full package name, ie, request.setAttribute("org.boncey.beans.bob", bob);.

Ok, no problem, but when you go to access that bean in the page you can no longer use <c:out value='{$org.boncey.beans.bob}'/> as it thinks that boncey is a property of bean org and it barfs.

To get around this you have to use an alternative syntax; <c:out value='{$requestScope["org.boncey.beans.bob"]}'/>.

That is nowhere near as neat and succint as the examples indicate.

Why on earth did they bother even offering syntax that goes completely against the best practice indicated in the docs.

Definitely a case of the left hand not knowing what the right hand is doing.

1 thought on “JSTL Gripe”

Leave a Reply

Your email address will not be published. Required fields are marked *