How do I iterate over a list in Jasper?

Go To StackoverFlow.com

2

I can't seem to find any information out there on this, but basically this is the situation. I need to display a set of strings, in this case they are peroids of hours. I'm trying to avoid writing a Java class but I can do that if it's necessary. Basically I want to display something like

1-2pm
2-3pm
3-4pm
4-5pm

I tried creating a list and a variable and then just doing

new ArrayList

assigning that to a variable and then doing a

$V{my_var}.add("1-2pm")

but when I assign that variable to a list it doesn't seem to work. How is this normally handled? I would ideally want a way to simply do this with the expression editor.

2012-04-04 19:35
by John Baker


1

You can use Arrays.asList(T... a) method in variable expression.

The example:

<variable name="listVar" class="java.util.List">
    <variableExpression><![CDATA[Arrays.asList(new String[] {"1-2pm", "2-3pm", "3-4pm", "4-5pm"})]]></variableExpression>
    <initialValueExpression><![CDATA[Arrays.asList(new String[] {"1-2pm", "2-3pm", "3-4pm", "4-5pm"})]]></initialValueExpression>
</variable>
2012-04-05 06:59
by Alex K
Since it's not changing, it probably makes sense to do this in a parameter instead - mdahlman 2012-04-06 04:40
Ads