title: How to pass ArrayList to JasperReports?
body: <p>I'm new to <code>JasperReports</code>. I want to pass <code>ArrayList</code> to subreport of subreport.</p>
  
  <p>I have master report which contains one subreport1 and this subreport1 encapsulate one<br>
  subreport2 inside.</p>
  
  <p>Now how to pass arrayList to subreport2?</p>
  
  <p>Like <code>MasterReport -&gt; SubReport -&gt; SubReport</code></p>
  
  <p><strong><em>Note</em></strong>: I am using <code>iReport</code> to create jasper template and passing datalist to jasper from my DAO java class.</p>
  
  <p>Below is my Form bean Class</p>
  
  <pre class="lang-java prettyprint-override"><code>public class CollatReportData extends BaseItem {
  
      private List&lt;CusipData&gt; listCusipData = null;
      private String dealerID = null;
      private String tripID = null;
      private String loanNo = null;
      private String dealerName = null;
      private String tripDealerLoan = null;
  
      public CollatReportData() {
          super();
      }
  
      public List&lt;CusipData&gt; getListCusipData() {
          return listCusipData;
      }
  
      public void setListCusipData(List&lt;CusipData&gt; listCusipData) {
          this.listCusipData = listCusipData;
      }
  
      public String getDealerID() {
          return dealerID;
      }
  
      public void setDealerID(String dealerID) {
          this.dealerID = dealerID;
      }
  
      public String getTripID() {
          return tripID;
      }
  
      public void setTripID(String tripID) {
          this.tripID = tripID;
      }
  } // and so on for other variables..
  </code></pre>
  
  <p>My DAO java class is below</p>
  
  <pre class="lang-java prettyprint-override"><code>public List&lt;Object&gt; getCollatData(String custName, String ctripid, 
          String dealerid, String userID) {
  
      final Connection conn = super.getCurrentConnection();
      String sqlQueryTrip = null;
      ResultSet rsCollat = null;
      String tripID = null;
      String dealerID = null;
      String cusSysID = null;
      String loanNo = null;
      String txnNo = null;
      String cusipNo = null;
      String cusipStatus = null;
      String parVal = null;
      String tripDealerLoan = null;
      String OldtripDealerLoan = "";
      String NewtripDealerLoan = "";
  
      CollatReportData reportData = null;
      CusipData cusipData = null;
      List listCusip = new ArrayList&lt;Object&gt;();
      List CollatList = new ArrayList&lt;Object&gt;();
      try {
          PreparedStatement pstmtTrip;
          sqlQueryTrip = "SELECT iscl_sys_id, iscl_trip_id, iscl_trip_dealer_id, "
                  + "iscl_cus_sys_id, iscl_bankref_cd, iscl_bdas_db_cd, "
                  + "iscl_loan_no, iscl_txn_no, iscl_cusip_no, iscl_status_cd, "
                  + "iscl_sec_de_tx, iscl_par_val_am, iscl_market_val_am, "
                  + "scl_pri_source_cd, iscl_colla_mar_val_am, iscl_mature_dt, "
                  + "iscl_sec_ty, iscl_sec_rt, iscl_sec_price_am, iscl_sec_factor, "
                  + "iscl_sec_margin, iscl_sec_accrued_am "
                  + "FROM BDS_DBA.INVCONF_SHELL_COLLAT "
                  + "WHERE iscl_cus_sys_id='" + custName + "'";
          pstmtTrip = conn.prepareStatement(sqlQueryTrip);
          rsCollat = pstmtTrip.executeQuery();
          if (rsCollat != null) {
              while (rsCollat.next()) {
                  tripID = rsCollat.getString("iscl_trip_id");
                  dealerID = rsCollat.getString("iscl_trip_dealer_id");
                  loanNo = rsCollat.getString("iscl_loan_no");
  
                  tripDealerLoan = tripID + dealerID + loanNo;
                  cusipData = new CusipData();
                  cusipData.setTripID(tripID);
                  cusipData.setCusipNo(cusipNo);
                  cusipData.setTripDealerLoan(tripDealerLoan);
  
                  listCusip.add(cusipData);
              } // end rsCollat
          } // end if
          CusipData cusipData1 = new CusipData();
          List CusipList = new ArrayList&lt;Object&gt;();
  
          for (int io = 0; io &lt; listCusip.size(); io++) {
              cusipData1 = (CusipData) listCusip.get(io);
              NewtripDealerLoan = cusipData1.getTripDealerLoan();
              tripID = cusipData1.getTripID();
              dealerID = cusipData1.getDealerID();
              loanNo = cusipData1.getLoanNo();
  
              if (NewtripDealerLoan.equalsIgnoreCase(OldtripDealerLoan) || OldtripDealerLoan.equalsIgnoreCase("")) {
                  CusipList.add(cusipData1);
  
              }
              if (!NewtripDealerLoan.equalsIgnoreCase(OldtripDealerLoan)) {
                  reportData = new CollatReportData();
                  reportData.setTripID(tripID);
                  reportData.setTripDealerLoan(NewtripDealerLoan);
                  reportData.setListCusipData(CusipList);
                  //and so on
                  //........
                  CollatList.add(reportData);
  
                  CusipList = null;
              }
              OldtripDealerLoan = NewtripDealerLoan;
          }
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          System.out.println("Inside LoanDetailDAO:strTripQuery:Exception" + sqlQueryTrip + e);
      }
  
      return CollatList;
  }
  </code></pre>
  
  <p>the above DAO class returns List and passing this <code>Arraylist</code> to Jasper template through Hashmap Param.</p>
  
  <p>Below is my sample  Master jasper template, from here i am passing ArrayList to subReport like</p>
  
  <pre class="lang-xml prettyprint-override"><code>     &lt;parameter name="list" isForPrompting="false" class="java.util.List"/&gt;
  
       &lt;detail&gt;
          &lt;band height="100"  isSplitAllowed="true" &gt;
              &lt;subreport  isUsingCache="true"&gt;
                  &lt;reportElement
                      x="30"
                      y="20"
                      width="170"
                      height="40"
                      key="subreport-1"/&gt;
                  &lt;dataSourceExpression&gt;&lt;![CDATA[new JRBeanCollectionDataSource( $P{list})]]&gt;&lt;/dataSourceExpression&gt;
                  &lt;subreportExpression  class="java.lang.String"&gt;&lt;![CDATA[$P{SUBREPORT_DIR} + "Collateral_SubReport1.jasper"]]&gt;&lt;/subreportExpression&gt;
              &lt;/subreport&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  </code></pre>
  
  <p>where <code>$p{list}</code> is <code>ArrayList</code>. and use this list to print in subReport1 asusual</p>
  
  <p>while running the code, i am getting the below error:</p>
  
  <p><code>Error retrieving field value from bean : tripID</code></p>
  
  <p>Thanks for your help in advance.</p>