Wednesday, April 12, 2006

The Significance and Importance of Quotes in JSTL EL

I just spent a few hours debuggung a null pointer in a Portlet JSP I'm writing. It's notoriously difficult as you need to deploy to see if you've cocked up and if the error is in your jsp, even decompiling the result can be of no use as this loses the comments and consequently the error of the line number is meaningless. I was reduced to cutting the page down to the barest minimum and then putting the bits back, one at a time to see where my mistake lay... (Ignore the wierd tags, that's there to get this to display properly)

As it turned out, the error was a particulary few-pixelled one. I had:


...c:when test="${not empty sessionBean.myProtoSubscription.mySubscribedEntityId}">
...c:choose>
...c:when test="{sessionBean.myProtoSubscription.mySubscribedEntityId" > 0}">
...


Where mySubscribedEntityId was a Long. I thought this would be the problem as the error was about a "null" and feared the Long > long transition would be the cluprit. How wrong was I. I'd just missed out two tiny quotes round the '0'. This now works:


...c:when test="${not empty sessionBean.myProtoSubscription.mySubscribedEntityId}">
...c:choose>
....c:when test="sessionBean.myProtoSubscription.mySubscribedEntityId"> '0'}">
...


Read more about JSTL EL "not empty" tags here

No comments: