13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data Sources and Query ExecutersFigure 11-13 JavaBeans set data sourceOnce again, the first thing to do is to specify the name of the new data source.The JavaBeans set data source uses an external class (named Factory) to produce some objects (the JavaBeans) that constitutethe data to pass to the report. Enter your Java class (the complete name of which you specify in the Factory class field) that hasa static method to instantiate different JavaBeans and to return them as a collection (java.util.Collection) or an array(Object[]). The method name and the return type have to be specified in the other fields of the window.Let’s see how to write this Factory class. Suppose that your data is represented by a set of objects of type PersonBean;following is the code of this class, which shows two fields: name (the person’s name) and age:Code Example 11-1PersonBean examplepublic class PersonBean{private String name = "";private int age = 0;public PersonBean(String name, int age){this.name = name;this.age = age;}public int getAge(){return age;}183

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!