scripted datasource cannot access public methods

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

scripted datasource cannot access public methods

Uli Schulze-Eyssing
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




_______________________________________________
birt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/birt-dev
Reply | Threaded
Open this post in threaded view
|

Re: scripted datasource cannot access public methods

Zorawar S.B.


On Tue, May 23, 2017 at 5:52 AM, Uli Schulze-Eyssing <[hidden email]> wrote:
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;

This code just has access to the class ReportDataService, so you would be able to invoke just static methods on it.

 


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


It is required to create the object to invoke the methods on it. Do it as,

importPackage(Packages.de.me.service); // this imports all classes in the package
var rds = new ReportDataService();
var books = rds.showMyBooks('Peter');

You could also create the object as such,
var rds = new Packages.de.me.service.ReportDataService();

Birt uses Rhino javascript engine for its scripting. 

Also, refer to the BIRT integration documentation under the *Miscellaneous* section another way of setting up Java objects for scripting.


Regards,
Zorawar 

_______________________________________________
birt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/birt-dev
Reply | Threaded
Open this post in threaded view
|

Re: scripted datasource cannot access public methods

Uli Schulze-Eyssing

What a great effect a little new could have!

I totally missed it.

Many thanks, Zorawar.

Regards,

Uli



Am 23.05.2017 um 18:01 schrieb Zorawar S.B.:


On Tue, May 23, 2017 at 5:52 AM, Uli Schulze-Eyssing <[hidden email]> wrote:
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;

This code just has access to the class ReportDataService, so you would be able to invoke just static methods on it.

 


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


It is required to create the object to invoke the methods on it. Do it as,

importPackage(Packages.de.me.service); // this imports all classes in the package
var rds = new ReportDataService();
var books = rds.showMyBooks('Peter');

You could also create the object as such,
var rds = new Packages.de.me.service.ReportDataService();

Birt uses Rhino javascript engine for its scripting. 

Also, refer to the BIRT integration documentation under the *Miscellaneous* section another way of setting up Java objects for scripting.


Regards,
Zorawar 


_______________________________________________
birt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/birt-dev


_______________________________________________
birt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/birt-dev