简体   繁体   中英

How do I iterate over a list in Jasper?

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM