Working with - java.util.Collection Parameter

0

Greetings,

I have Parameter $P{Names} with class: java.util.Collection and It has 2 values: "Name1" and "Name2"

I've created Textfield with an expression: "Username: " + $P{Names}

What I want to receive in report is:

Username: Name1

Username: Name2

What I received is report is:

Username: [Name1,Name2]

Please help how can I fix this problem? How to separate values passed from collection Parameter?

bessokefashvili's picture
Joined: Oct 4 2017 - 5:43am
Last seen: 2 months 1 week ago

4 Answers:

0

The response you are getting is correct. 
Best would be to rather use a ArrayList and then .get(YouIndexNumber) to get the value. Then just increment  your YouIndexNumber. 
Collection are not guaranteed to have fixed indices... 

joseng62's picture
610
Joined: Dec 5 2014 - 2:43am
Last seen: 15 hours 12 min ago
0

 

@joseng62

Thank you for the reply, it worked but partially.

When I've indicated  IndexNumber - it returned only one specific value

for example when I've entered: $P{Names} .get(0) it returned only the first value.

What I need is a dynamic solution - that will return all the values separately so that I didn't have to write each IndexNumber separately and create multiple textfields.

 

 

bessokefashvili's picture
Joined: Oct 4 2017 - 5:43am
Last seen: 2 months 1 week ago
0

perhaps just an idea.... use simple java objects instead String Collection:

something like:

public class User{
 
String userName;
 
public User(String name){
 
this.userName = name;
 
}
 
public String getUserName(){
 
return this.userName;
 
}
 
}

and when you create your Collection<User> somewhere in your java code and pass this as paramater "userList" to the fill process then you easily could create a

JRBeanCollectionDataSource for a SubReport or jus a ListElement DataSourceExpression right in the jrxml-design

new JRBeanCollectionDataSource($P{userList})

Perhaps you could also create adHoc another DataSource from just an ArrayList<String> or whatever your parameter is typed of. Just take a look at the provided DataSource Implementations: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRDataSource.html

hth + regards

C-Box

C-Box's picture
1622
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 hour 49 min ago
0

hi there

what if I want to pass this array of objects via Rest.

Is there any posible way for rest parameters to take array of objects

Thanks a lot

bessokefashvili's picture
Joined: Oct 4 2017 - 5:43am
Last seen: 2 months 1 week ago
Feedback