Java Reference
In-Depth Information
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
In this example, we populate an array with AircraftData objects, which
contain the data to be displayed in the report. We then pass this array to the
constructor of JRBeanArrayDataSource . Finally, we pass the new instance of
JRBeanArrayDataSource to the JasperRunManager.runReportToPdfStream()
method, which generates the report and exports it to PDF format on the fly. The
generated report is then displayed on the browser.
If we need to group our Beans in a Collection instead of an array, JasperReports provides
the class.
This class has only one public constructor, which takes a java.util.Collection
object as its only parameter. It expects this collection to be populated with JavaBeans
that can be used to populate the report. The following example demonstrates how to
use JRBeanCollectionDataSource to populate our reports:
package net.ensode.jasperbook;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JasperRunManager;
public class BeanCollectionDSReportServlet extends HttpServlet
private JRDataSource createReportDataSource()
Search WWH ::

Custom Search