Saturday, October 16, 2010

JSTL snippets

Simple when you know how. Frustrating and time consuming when you don’t
If/ else
Because of the xml format we can’t have a
<c:if test=”${actionBean.test}”>
Instead we have to use choose, when and otherwise.
<c:when test="${actionBean.test}”>

Looping through lists
Realated to above, I was trying to test if a list was populated.
First attempt was
<c:when test="${actionBean.result.size>0}">
javax.el.PropertyNotFoundException: The class 'java.util.Collections$Synchronize
dCollection' does not have the property 'size'.
at javax.el.BeanELResolver.getBeanProperty(
at javax.el.BeanELResolver.getValue(
at javax.el.CompositeELResolver.getValue(
at com.sun.el.parser.AstValue.getValue(
at com.sun.el.parser.AstGreaterThan.getValue(
Truncated. see log file for complete stacktrace
Solution is to use Not Empty
<c:when test="${not empty actionBean.result}">

No comments: