title: How to generate dynamic tables in JasperReports using lists
body: <p>I am trying to generate a tabular report in Jasper. Specifically I am trying to iterate through a list in a table like this: </p>
  
  <p><strong>Java Code:</strong></p>
  
  <pre><code>List&lt;String&gt; severity = (List&lt;String&gt;)session.getAttribute("severity"); 
  List&lt;String&gt; messages = (List&lt;String&gt;)session.getAttribute("messages");
  
  LinkedHashMap parameters = new LinkedHashMap();
  parameters.put("severity", severity);
  parameters.put("messages", messages);
  
  jPrint = JasperFillManager.fillReport(jasperreport,parameters,new JREmptyDataSource());
  JasperExportManager.exportReportToPdfStream(jPrint,baos);    
  </code></pre>
  
  <p><strong>JRXML</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="jasper_report_template" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3d5ea75-61fe-4bd0-a2ef-43652ca82bb5"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/&gt;
      &lt;queryString&gt;
          &lt;![CDATA[]]&gt;
      &lt;/queryString&gt;
      &lt;field name="severity" class="java.util.List"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[severity]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="messages" class="java.util.List"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[messages]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;columnHeader&gt;
          &lt;band height="23" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement mode="Opaque" x="0" y="-180" width="535" height="15" backcolor="#70A9A9" uuid="9b5b79e0-e146-41d9-b665-6cf9441c44f7"/&gt;
                  &lt;box&gt;
                      &lt;bottomPen lineWidth="1.0" lineColor="#CCCCCC"/&gt;
                  &lt;/box&gt;
                  &lt;text&gt;&lt;![CDATA[ ]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="290" y="0" width="121" height="15" uuid="427a0dc3-acc5-445d-afdf-325f56220d5b"/&gt;
                  &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                      &lt;font isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Error Severity]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="3" width="136" height="15" uuid="9d05c15b-478c-49d3-a334-c5d6bfc62e53"/&gt;
                  &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                      &lt;font isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Erorr Messages]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="16" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement mode="Opaque" x="0" y="0" width="535" height="14" backcolor="#E5ECF9" uuid="b0ac6c6e-6d86-44de-801c-fcb85f1c5cb7"/&gt;
                  &lt;box&gt;
                      &lt;bottomPen lineWidth="0.25" lineColor="#CCCCCC"/&gt;
                  &lt;/box&gt;
                  &lt;text&gt;&lt;![CDATA[ ]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;textField&gt;
                  &lt;reportElement x="290" y="0" width="121" height="15" uuid="d106ecf9-2dc8-49fb-b63c-e348b96f871d"/&gt;
                  &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{severity}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="136" height="15" uuid="d106ecf9-2dc8-49fb-b63c-e348b96f871d"/&gt;
                  &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{messages}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>So My questions are:</p>
  
  <p>1) How to print these lists in Jrxml?</p>
  
  <p>2) Is that right way to iterate through a list in JRXML?</p>
  
  <p>3) How to write JRXML code to iterate List? (is subreport useful in this scenario?)</p>