Java Reference
In-Depth Information
class is very similar to using JRMapArrayDataSource . The only difference is that
we pass a Collection of Map objects to its constructor, instead of an array. The
following example illustrates this:
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 MapCollectionDSReportServlet extends HttpServlet
private JRDataSource createReportDataSource()
JRMapCollectionDataSource dataSource;
Collection reportRows = initializeMapCollection();
dataSource = new JRMapCollectionDataSource(reportRows);
return dataSource;
private Collection initializeMapCollection()
ArrayList reportRows = new ArrayList();
HashMap row1Map = new HashMap();
HashMap row2Map = new HashMap();
HashMap row3Map = new HashMap();
HashMap row4Map = new HashMap();
row1Map.put("tail_num", "N263Y");
row1Map.put("aircraft_serial", "T-11");
row1Map.put("aircraft_model", "39 ROSCOE TRNR RACER");
row1Map.put("engine_model", "R1830 SERIES");
row2Map.put("tail_num", "N4087X");
row2Map.put("aircraft_serial", "BA100-163");
Search WWH ::

Custom Search