I would like to use the <jt:if> tag to check if a collection if empty, and if so output a blank cell (so that cell formatting is kept) otherwise output the value from the collection. Something like this pseudo code:
I would use the form of the jt:if tag that takes a body. The body of an if tag, if present, is like the then attribute of a bodiless if tag. The elseAction attribute is valid for if tags with a body, and "clear" seems to do what you want, i.e. clear the cell without shifting, leaving formatting in place.
<jt:if test="${header.accountExecutives.size() != 0}" elseaction="clear">
<jt:foreach items="${header.accountExecutives}" var="ae">${ae.name}</jt:foreach>
</jt:if>
When I try as above approach , it gives me java.lang.NullPointerException: null
at org.apache.commons.jexl2.Interpreter.sizeOf(Interpreter.java:1474) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1398) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.parser.ASTSizeMethod.jjtAccept(ASTSizeMethod.java:18) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1317) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.parser.ASTReference.jjtAccept(ASTReference.java:18) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1195) ~[commons-jexl-2.1.1.jar:2.1.1]
What is the wrong with this?
Last edit: thrishala 2021-04-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to use the <jt:if> tag to check if a collection if empty, and if so output a blank cell (so that cell formatting is kept) otherwise output the value from the collection. Something like this pseudo code:
I don't know how to use the if tag and then in a condition to loop through a collection? Is this possible or is there some other way?
Last edit: Mark Vejvoda 2014-04-14
I would use the form of the
jt:if
tag that takes a body. The body of an if tag, if present, is like thethen
attribute of a bodilessif
tag. TheelseAction
attribute is valid forif
tags with a body, and"clear"
seems to do what you want, i.e. clear the cell without shifting, leaving formatting in place.Try the following:
That should all be in one cell. It's a lot for one cell, but that should work.
Yes works great, thanks. The clear keeps cell formatting which is perfect.
<jt:if test="${header.accountExecutives.size() != 0}" elseaction="clear">
<jt:foreach items="${header.accountExecutives}" var="ae">${ae.name}</jt:foreach>
</jt:if>
When I try as above approach , it gives me java.lang.NullPointerException: null
at org.apache.commons.jexl2.Interpreter.sizeOf(Interpreter.java:1474) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1398) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.parser.ASTSizeMethod.jjtAccept(ASTSizeMethod.java:18) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1317) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.parser.ASTReference.jjtAccept(ASTReference.java:18) ~[commons-jexl-2.1.1.jar:2.1.1]
at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1195) ~[commons-jexl-2.1.1.jar:2.1.1]
What is the wrong with this?
Last edit: thrishala 2021-04-29
Maybe the expression on which you call .size() evaluates to null.
Can you share the expressions you're using in your jexl tags?
Thanks for replying. Yes you are correct .Finally myself identified the issue which is with the the data set ,I have used .
Last edit: thrishala 2021-05-03