[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[birt-dev] scripted datasource cannot access public methods

Hi,
IÂm trying to set up a scripted Datasource using pojos from my app (java 1.8).
I embedded a reportengine (4.4.0) in my app via maven and created a report with a scripted datasourse. The pojos can be seen by the report.


bookSrv = Packages.de.me.service.ReportDataService;


works.

I can access static methods of my object, but whatever i try, accessing public methods or fields results in an exception.

So

books = bookSrv.books;

gives
org.mozilla.javascript.EvaluatorException: Java class "de.me.service.ReportDataService" has no public instance field or method named "books". (/report/data-sets/script-data-set[@id="5"]/method[@name="open"]#11)
or


books = bookSrv.showMyBooks('Peter');


gives
org.mozilla.javascript.EvaluatorException: Java class "de.my.service.ReportDataService" has no public instance field or method named "showMyBooks". (/report/data-sets/script-data-set[@id="5"]/method[@name="open"]#11)


But:

books = Packages.me.tdesk.service.ReportDataService.myBooksStatic('Peter');

works like expected. (Simply a static wrapper around my method)



here is my java class:

package de.me.service;

import de.me.model.dto.BookDto;

import java.util.ArrayList;

import java.util.List;

public class ReportDataService {

    public ReportDataService() {

        books = showMyBooks("Peter");

        System.out.println("ReportDataService.init()");

    }

    private List<BookDto> books;

    public List<BookDto> getBooks() {

        return books;

    }

    public void setBooks(List<BookDto> books) {

        this.books = books;

    }

    public List<BookDto> showMyBooks(String commodity){

        BookDto dto = new BookDto(12l, "otto", "My", 12l);

        List<BookDto> books = new ArrayList<>();

        books.add(dto);

        dto = new BookDto(122l, "paul", "My", 122l);

        books.add(dto);

        return books;

    }

    public static List<BookDto> myBooksStatic(String commodity){

        ReportDataService rep = new ReportDataService();

        return rep.showMyBooks(commodity);

    }

}


Many thanks Uli