scripted datasource cannot access public methods
Options
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">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.</p>
<pre class="_prettyXprint">
bookSrv = Packages.de.me.service.ReportDataService;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works.</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">I can access static methods of my object, but whatever i try, accessing public methods or fields results in an exception.</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">So</p>
<pre class="_prettyXprint">
books = bookSrv.books;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">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</p>
<pre class="_prettyXprint">
books = bookSrv.showMyBooks('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">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)</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">But:</p>
<pre class="_prettyXprint">
books = Packages.me.tdesk.service.ReportDataService.myBooksStatic('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works like expected. (Simply a static wrapper around my method)</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">here is my java class:</p>
<div>
<pre class="_prettyXprint">
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);
}
}
</pre>
</div>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Many thanks,</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Uli</p>
<pre class="_prettyXprint">
bookSrv = Packages.de.me.service.ReportDataService;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works.</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">I can access static methods of my object, but whatever i try, accessing public methods or fields results in an exception.</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">So</p>
<pre class="_prettyXprint">
books = bookSrv.books;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">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</p>
<pre class="_prettyXprint">
books = bookSrv.showMyBooks('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">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)</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">But:</p>
<pre class="_prettyXprint">
books = Packages.me.tdesk.service.ReportDataService.myBooksStatic('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works like expected. (Simply a static wrapper around my method)</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">here is my java class:</p>
<div>
<pre class="_prettyXprint">
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);
}
}
</pre>
</div>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Many thanks,</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Uli</p>
0
Comments
-
<p>Hi Uli, you should use importPackage() to make your class available like the example and tips shown at <a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/topic/40314-using-a-java-object-to-access-a-data-source/'>http://developer.actuate.com/community/forum/index.php?/topic/40314-using-a-java-object-to-access-a-data-source/</a></p>Warning No formatter is installed for the format ipb0
-
<p><strong>Note</strong>: <em>Posting my answer from the BIRT mailing list which worked for Uli for future reference</em>.</p>
<pre class="_prettyXprint">
bookSrv = Packages.de.me.service.ReportDataService;</pre>
<p>The above code just has access to the class ReportDataService, so you would be able to invoke just static methods on it.</p>
<p> </p>
<div>
<div>
<div>It is required to create the object to invoke the methods on it. Do it as,</div>
<pre class="_prettyXprint">
importPackage(Packages.de.me.service); // this imports all classes in the package
var rds = new ReportDataService();
var books = rds.showMyBooks('Peter');
</pre>
<p>You could also create the object as such,</p>
</div>
<div>
<pre class="_prettyXprint">
var rds = new Packages.de.me.service.ReportDataService();</pre>
BIRT uses Rhino javascript engine for its scripting. </div>
<div><a data-ipb='nomediaparse' href='https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java'>https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java</a></div>
</div>
<div> </div>
<div>Also, refer to the BIRT integration documentation under the *Miscellaneous* section another way of setting up Java objects for scripting.</div>
<p><a data-ipb='nomediaparse' href='http://www.eclipse.org/birt/documentation/integrating/reapi.php'>http://www.eclipse.org/birt/documentation/integrating/reapi.php</a></p>0
Categories
- All Categories
- 109 Developer Announcements
- 49 Articles
- 100 General Questions
- 122 IM Services
- 40 OpenText Hackathon
- 31 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 897 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 122 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management