Search code examples
javabirtpojo

cant get BIRT to work with POJO


I am new to java and reporting tool BIRT, I am trying to create a simple report using Pojo in Birt but I can't get it to work I create my java classes in other project and generate a jar file after that I use it to create a data source but when I try to create a data set it doesnt work, I couldn't select classes to proceed

enter image description here

    package com.test.pojoproject;

import java.io.Serializable;

public class Person implements Serializable {

     /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int id;
        private String name;
        private String address;

        public Person(){

        }

        public int getId() {
            return id;
        }

        public String getName() {
            return name;
        }

        public String getAddress() {
            return address;
        }

        public void setId(int id) {
            this.id = id;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAddress(String address) {
            this.address = address;
        }

}

    package com.test.pojoproject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Main implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private static List<Person> list = new ArrayList<Person>();
    public static void main(String[] args) {
        Main.generateData();
        Main.getList();

        // display created list
        //list.forEach(person -> System.out.println(person.getName()));


    }

    public static void generateData(){
        List<Person> list = new ArrayList<Person>();
        for (int i = 0; i < 30; i++) {
            Person  person = new Person();
            person.setId(i+1);
            person.setName("person " + (i+1));
            person.setAddress("address " + (i+1));
            list.add(person);
        }
        Main.list = list;
    }

    public static List<Person> getList(){
        return Main.list;
    }

}

Solution

  • I found a solution BIRT needs to use a class withe methodes open, next and close I will post my dataset class below

        package com.test.pojoproject;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    
    public class PersonDataSet {
    
        public Iterator<Person> itr;
    
        public List<Person> getPersons() {
            List<Person> persons = new ArrayList<Person>();
    
            for (int i = 0; i < 30; i++) {
                Person  person = new Person();
                person.setId(i+1);
                person.setName("person " + (i+1));
                person.setAddress("address " + (i+1));
                persons.add(person);
            }
    
            return persons;
        }
    
        public void open(Object obj, Map<String,Object> map) {
        }
    
        public Object next() {
            if (itr == null)
                itr = getPersons().iterator();
            if (itr.hasNext())
                return itr.next();
            return null;
        }
    
        public void close() {
        }
    
    }