Передача коллекции Java-бинов в качестве источника данных в Jasper, как спроектировать это в ireports

Мне нужно создать отчет, который отображает данные из коллекции (Say List). Этот список содержит несколько POJO.

POJO заполняются уровнем доступа к данным приложения. Как создать шаблон отчета для этого требования в iReports?


person Vaishak Suresh    schedule 15.06.2010    source источник


Ответы (3)


Используйте для своего отчета JRBeanCollectionDataSource.

person Bozho    schedule 15.06.2010
comment
Разве я не должен использовать набор данных JavaBean? - person Vaishak Suresh; 15.06.2010
comment
для коллекции бобов это то, что нужно использовать :) - person Bozho; 15.06.2010

Ok! Нашел ответ. Шаги, как показано ниже.

  1. Скомпилируйте классы компонентов и создайте файл JAR. Это должен иметь полный пакет
  2. Добавьте эту банку в папку LIB в ireports
  3. Создайте класс фабрики/оболочки с методом createBeanCollection, заполняющим коллекцию.
  4. Используйте пакет верхнего уровня этого класса в качестве пути к классу в ireports
  5. Используйте этот класс в качестве источника данных JavaBean с методом.

Как только все это будет сделано, создайте отчет с новым источником данных и в запросе отчета укажите полное доменное имя для Java-бина и добавьте нужное поле.

person Vaishak Suresh    schedule 15.06.2010
comment
не могли бы вы уточнить шаг 3 - person Alekya; 17.04.2019

BankDetailsList list = new BankDetailsList();       
ArrayList<BankDetails> lst = list.getDataBeanList();        
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lst);

Здесь BankDetails является POJO

public class BankDetails {

    public String bank_name;
    public Account account;
    public String custodian_account;
    public String custodian_name;
    public String agreement_type;
    public double exposure;
    public double collateral;
    public double independant_amount;
        public double net_exposure;

    BankDetails(String b_name, Account acc, String cust_account,
        String cust_name, String agr_type, double expo, double collat,
        double independant_amt, double net_exp) {

        this.bank_name = b_name;
        this.account = acc;
        this.custodian_account = cust_account;
        this.custodian_name = cust_name;
        this.agreement_type = agr_type;
        this.exposure = expo;
        this.collateral = collat;
        this.independant_amount = independant_amt;
        this.net_exposure = net_exp;
    }

    public String getBank_name() {
        return bank_name;
    }
    public void setBank_name(String bank_name) {
        this.bank_name = bank_name;
    }
    public Account getAccount() {
        return account;
    }
    public void setAccount(Account account) {
        this.account = account;
    }
    public String getCustodian_account() {
        return custodian_account;
    }
    public void setCustodian_account(String custodian_account) {
        this.custodian_account = custodian_account;
    }
    public String getCustodian_name() {
        return custodian_name;
    }
    public void setCustodian_name(String custodian_name) {
        this.custodian_name = custodian_name;
    }
    public String getAgreement_type() {
        return agreement_type;
    }
    public void setAgreement_type(String agreement_type) {
        this.agreement_type = agreement_type;
    }
    public double getExposure() {
        return exposure;
    }
    public void setExposure(double exposure) {
        this.exposure = exposure;
    }
    public double getCollateral() {
        return collateral;
    }
    public void setCollateral(double collateral) {
        this.collateral = collateral;
    }
    public double getIndependant_amount() {
        return independant_amount;
    }
    public void setIndependant_amount(double independant_amount) {
        this.independant_amount = independant_amount;
    }
    public double getNet_exposure() {
        return net_exposure;
    }
    public void setNet_exposure(double net_exposure) {
        this.net_exposure = net_exposure;
    }
}

Аккаунт POJO:

public class Account {

    public int account_id;
    public String account_name;

    Account(int acc_id, String acc_name){
        this.account_id = acc_id;
        this.account_name = acc_name;
    }

    public int getAccount_id() {
        return account_id;
    }

    public void setAccount_id(int account_id) {
        this.account_id = account_id;
    }

    public String getAccount_name() {
        return account_name;
    }

    public void setAccount_name(String account_name) {
        this.account_name = account_name;
    }
}
person Dark Army    schedule 17.08.2015