JasperReports allows us to use instances of any class implementing the java.util.Map
interface as a datasource. We can use either an array or a collection of Map
objects to generate a report. Each Map
in the collection or array is a record that will be used to generate the data for each row inside the<detail>
tag of the report. The JasperReports API provides an implementation of net.sf.jasperreports.engine.JRDataSource
called net.sf.jasperreports.engine.data.JRMapArrayDataSource
that will enable us to use an array of Map
objects as a datasource. The following example demonstrates this class in action:
package net.ensode.jasperbook; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax...