views:

25

answers:

0

Hi Experts,

I am completely new to jasper reports,i want to pass ArrayList to subreport and also subreport of subreport.

i have master report which contains one subreport1 and this subreport1 encapsulate one subreport2 inside. Like MasterReport <- SubReport1 <- SubReport2

Now how to pass arrayList to subreport1 and subreport2 ?

Note: 1)i am using ireport to create jasper template.and passing datalist to jasper from my DAO java class.

2) CusipData is another Form Bean class containing setter(),getter() methods

3)CollatReportData is also Form Bean containing setter(),getter() methods

Below is my Form bean Class

     public class CollatReportData extends BaseItem{
       private List<CusipData>   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<CusipData> getListCusipData() {
         return listCusipData;
     }
    public void setListCusipData(List<CusipData> 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..

My DAO java class is below[Returning List]

public List<Object> getCollatData(String custName,String ctripid,String dealerid,String userID){

String tripID =null;
String dealerID =null;
String loanNo =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<Object>();
List CollatList = new ArrayList<Object>();
try {

            PreparedStatement pstmtTrip;
        sqlQueryTrip = "SELECT * 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");
                     and so on....
               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<Object>();

            for (int io=0;io<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) {
                     System.out.println(e);
        }

     return CollatList;
  }

 }

the above DAO class returns List[inside list contains beanobject[reportData]] and passing this "Arraylist" to Jasper template through Hashmap Param.

Below is my sample Master jasper template, from here i am passing ArrayList to subReport like

 <parameter name="list" isForPrompting="false" class="java.util.List"/>

 <detail>
    <band height="100"  isSplitAllowed="true" >
        <subreport  isUsingCache="true">
            <reportElement
                x="30"
                y="20"
                width="170"
                height="40"
                key="subreport-1"/>
            <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource( $P{list})]]></dataSourceExpression>
            <subreportExpression  class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "Collateral_SubReport1.jasper"]]></subreportExpression>
        </subreport>
    </band>
</detail>

where $p{list} [list->parameter name in jrxml tempate] is arrayList get from hashMap param. and use this list to print in subReport1. while running the code , i am getting the below error

    "Error retrieving field value from bean : tripID" 
     JRFillSubrepo E net.sf.jasperreports.engine.fill.JRFillSubreport prepare Fill 1855483544: exception
                             net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : tripID
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:116)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:93)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:104)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:813)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:777)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1106)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:111)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:763)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:688)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:526)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:63)
at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:209)
at java.lang.Thread.run(Thread.java:810)
   Caused by: java.lang.NoSuchMethodException: Unknown property 'tripID'

Note:(where tripID is declared variable in Formbean class with setter() and getter() methods)

I am fighting with this error for past 1 week,not able to fix.

Help me in this issue.