ycohen Posted April 23, 2013 Share Posted April 23, 2013 I've got a Collection of Java objects with getters that I want to use to populate a report in Jasper Server. I've searched and found http://enholm.net/index.php/blog/jasper-reports-custom-data-source-example/, but it uses an applicationContext.xml which is different from the one that I've got in JasperServer, and I don't know how to adjust it.How would I use a Collection in JasperServer? Link to comment Share on other sites More sharing options...
Ankur Gupta Posted May 9, 2013 Share Posted May 9, 2013 Hi,What you need to do is follow the steps described -1. First you need to create bean like: public class PersonBean{private String name = "";private int age = 0;public PersonBean(String name, int age){this.name = name;this.age = age;}public int getAge(){return age;} public String getName() { return name; } } 2. Then you need to make a class that returns a collection fo example: public class Factory { public static java.util.Collection generateCollection() { java.util.Vector collection = new java.util.Vector(); collection.add(new PersonBean("Ted", 20) ); collection.add(new PersonBean("Jack", 34) ); collection.add(new PersonBean("Bob", 56) ); collection.add(new PersonBean("Alice",12) ); collection.add(new PersonBean("Robin",22) ); collection.add(new PersonBean("Peter",28) ); return collection; } } 3. Then you need to compile it and add it as an jar in the folder structure(C:Program Filesjasperreports-server-x.xapache-tomcatlib.).4. Then while defining the datasource you need to set the following based on the above snippet and set the values as-- Factory class: FactoryMethod to call: generateCollectionReturn type: Collection of JavaBean Then you can test the connection and you are good to go I hope that above explanation helps your cause. Regards,Ankur Link to comment Share on other sites More sharing options...
kjell1906 Posted June 30, 2013 Share Posted June 30, 2013 I have tied this procedure, but I got Connection Failed i JasperSever Data Connection. I have used Bean Data Source. Link to comment Share on other sites More sharing options...
user4561 Posted December 16, 2013 Share Posted December 16, 2013 Hi, I got the same 'Connection failed' error. I created Bean Data source in JasperReports Server, and added following information: Bean Name: Factory Bean Method: generateCollection But I couldn't see 'ReturnType' field. I am using JasperServer 5.5.0. Would really appreciate nay help. Link to comment Share on other sites More sharing options...
Ankur Gupta Posted December 16, 2013 Share Posted December 16, 2013 Hi folks,Sorry for the trouble actually there is a step missed, after the step 3,You need to add the Jar file to the classpath also.you could add in the classpath by, Tools(in the Menu bar) --> select the Options --> Select the tab CLASSPATH --> Click on Add Jar One thing more I want to clearify is that you need to put both these bean as well as the static factory function in one single java class and access it in setting up the datasource. So suppose you have the package name as com.sample.jasper and your class containing both the bean as well as the factory function is JasperBeanData so the expression for the Bean: com.sample.jasper.JasperBeanDataFactory Class : generateCollection. Hope that this helps establishing the connection.Please do reply if more clearifications are required. Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
manojshishodia Posted January 24, 2014 Share Posted January 24, 2014 Which classpath is this. Is it the classpath of JasperServer? I dodnt find Tools and those options in jasperserver page. Where exactly we should enter that jar. Link to comment Share on other sites More sharing options...
Ankur Gupta Posted January 24, 2014 Share Posted January 24, 2014 The classpath is of iReport/Jaspersoft Studio, If you want to use it in jasper server you need to add the jar as the resource to the report. Link to comment Share on other sites More sharing options...
manojshishodia Posted January 27, 2014 Share Posted January 27, 2014 Hi, I have added the jar in resource to the report in jasperserver. Also have created the jrxml in ireport having only two fields i.e name and age. While adding data sources i am getting connection failed. I have deployed jasperserver in jboss. Also addded that jar in lib of jboss. What may be the reason of getting connection failed. Any help is appreciated. Thanks in advance Link to comment Share on other sites More sharing options...
jpmillan Posted April 7, 2016 Share Posted April 7, 2016 Im also having somewhat the same issues (in 6.2.1), i created a detailed step by step of what i did. http://stackoverflow.com/questions/36443248/how-can-jaspersoft-bean-datasource-be-deployed-in-jasper-server does it need to put the jar file in the /lib, the add the jar as a report resource? isnt this redundant? and also, i tried this and still the bean is not recognized. Link to comment Share on other sites More sharing options...
Jaya5 Posted August 15, 2016 Share Posted August 15, 2016 hi do you need to add the bean to WEB-INF file in the server and restart server. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now