We are facing a problem while using Page break in Jasper Reports. we are having a main report which calls the Subreport and the subreport is having a table and 5 more sub reports.
we are passing a arraylist to the main report.The arraylist contains the Vo's for the reord selected from the user.The VO contains values for the fields in the sub report and other 5 sub repports in the sub report. The main report will call the sub report for each vo in the arraylist. We need each record to be displayed in separate pages in the same PDF. There are cases that the 5 subReports in the sub report won't be displayed only the table in the sub report will be displayed. We need each record to be displayed in separate pages regardless of whether the sub report contains other 5 sub reports. We tried to put a page break after each record so that the next record comes in separate page but we got an exception element type 'break' must be declared. QcanEnquiryDataSource .java(Main Report DataSource Code) package com.psa.citos.vops.ots.datasource.qcan; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Iterator; import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; import com.psa.citos.vops.ots.util.OTSLoggerUtil; import com.psa.citos.vops.ots.vo.qcan.ReportResultVo; public class QcanEnquiryDataSource implements JRDataSource { public static OTSLoggerUtil logger = new OTSLoggerUtil("com.psa.citos.vops.ots.datasource.qcan.QcanEnquiryDataSource"); public ArrayList qcanDetailsList = null; public Iterator qcanDetailsItr = null; public ReportResultVo reportResultVo = null; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); /** * Constructor for creating the Qcan Report Main Datasource. * @param qcanDetailsList */ public QcanEnquiryDataSource(ArrayList qcanDetailsList) { try { this.qcanDetailsList = qcanDetailsList; logger.debug("qcanDetailsList Size : " + this.qcanDetailsList.size()); if(this.qcanDetailsList != null) { this.qcanDetailsItr = this.qcanDetailsList.iterator(); } } catch(Exception exception) { logger.error("Exception caught in QcanEnquiryDataSource ", exception); } } /** * Call back method. Based on this method call, the Report fields will be populated * and displayed. * @return boolean * @throws JRException */ public boolean next() throws JRException { try { reportResultVo = qcanDetailsItr.hasNext() ? (ReportResultVo) qcanDetailsItr.next() : null; } catch(Exception exception) { logger.error("Exception caught in next() of QcanEnquiryDataSource ", exception); return false; } return (reportResultVo != null); } /** * This is also a call back method. This will supply the values for each fields * displayed in the report. * @param jrField * @return Object * @throws JRException */ public Object getFieldValue(JRField jrField) throws JRException { Object fieldValue = null; try { // The below will return the current filed name to be populated. String fieldName = jrField.getName(); if(fieldName.equals("ListQcanDetails")) { System.out.println("getReportResultList in QcanEnquiryDataSource : "+reportResultVo.getReportResultList()); fieldValue = new QcanSubReportDataSource(reportResultVo.getReportResultList()); } } catch(Exception exception) { logger.error("Exception caught in getFieldValue() of QcanEnquiryDataSource ", exception); } return fieldValue; } } QcanSubReportDataSource .java(Sub Report DataSource Code) package com.psa.citos.vops.ots.datasource.qcan; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; import com.psa.citos.common.util.CPropertiesFactory; import com.psa.citos.vops.ots.util.OTSLoggerUtil; import com.psa.citos.vops.ots.util.OtsUtilities; import com.psa.citos.vops.ots.vo.qcan.VesselPerformanceVo; /** * This is the Datasource for the Parent Report for the QCAN Report. It contains the * call back methods. Based on these methods the reports sections will be populated. */ public class QcanSubReportDataSource implements JRDataSource { public static OTSLoggerUtil logger = new OTSLoggerUtil("com.psa.citos.vops.ots.datasource.qcan.QcanSubReportDataSource"); public ArrayList qcanDetailsList = null; public Iterator qcanDetailsItr = null; public VesselPerformanceVo vesselPerformanceVo = null; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); /** * Constructor for creating the Qcan Report Main Datasource. * @param qcanDetailsList */ public QcanSubReportDataSource(ArrayList qcanDetailsList) { try { this.qcanDetailsList = qcanDetailsList; logger.debug("qcanDetailsList Size : " + this.qcanDetailsList.size()); if(this.qcanDetailsList != null) { this.qcanDetailsItr = this.qcanDetailsList.iterator(); } } catch(Exception exception) { logger.error("Exception caught in QcanDataSource ", exception); } } /** * Call back method. Based on this method call, the Report fields will be populated * and displayed. * @return boolean * @throws JRException */ public boolean next() throws JRException { try { vesselPerformanceVo = qcanDetailsItr.hasNext() ? (VesselPerformanceVo) qcanDetailsItr.next() : null; } catch(Exception exception) { logger.error("Exception caught in next() of QcanDataSource ", exception); return false; } return (vesselPerformanceVo != null); } /** * This is also a call back method. This will supply the values for each fields * displayed in the report. * @param jrField * @return Object * @throws JRException */ public Object getFieldValue(JRField jrField) throws JRException { Object fieldValue = null; try { // The below will return the current filed name to be populated. String fieldName = jrField.getName(); if(fieldName.equals("berthingSeqNum")) { fieldValue = vesselPerformanceVo.getBerth_seq_n(); } else if(fieldName.equals("curDate")) { fieldValue = sdf.format(new Date()); } else if(fieldName.equals("VSL")) { fieldValue = vesselPerformanceVo.getVessel_m(); } else if(fieldName.equals("VOY")) { fieldValue = vesselPerformanceVo.getVoyage_out_n(); } else if(fieldName.equals("BNO")) { //added for berth_n >9 for T terminal. String terminal_code = vesselPerformanceVo.getTerminal_c(); String berth_num = vesselPerformanceVo.getBerth_n(); if(terminal_code != null && terminal_code.equalsIgnoreCase("T") && berth_num != null){ if(Integer.parseInt(berth_num) >= 9){ int new_berth_num = Integer.parseInt(berth_num) - 4; berth_num= OtsUtilities.formatBerthNumber(new Integer(String.valueOf(new_berth_num))); } } fieldValue = terminal_code + " " + berth_num; //fieldValue = vesselPerformanceVo.getTerminal_c() + " " + vesselPerformanceVo.getBerth_n(); } else if(fieldName.equals("BDATE")) { fieldValue = vesselPerformanceVo.getAtb_dt(); } else if(fieldName.equals("DEPDATE")) { fieldValue = vesselPerformanceVo.getAtu_dt(); } else if(fieldName.equals("VIN")) { fieldValue = vesselPerformanceVo.getVin_n(); } else if(fieldName.equals("TIMESTART")) { fieldValue = vesselPerformanceVo.getStart_dt(); } else if(fieldName.equals("TIMEEND")) { fieldValue = vesselPerformanceVo.getEnd_dt(); } else if(fieldName.equals("BERTHING")) { fieldValue = vesselPerformanceVo.getBerthing(); } else if(fieldName.equals("VSLHRS")) { fieldValue = vesselPerformanceVo.getVessel_duration_q(); } else if(fieldName.equals("MOVEQ")) { fieldValue = vesselPerformanceVo.getMove_q(); } else if(fieldName.equals("VSLRT")) { fieldValue = vesselPerformanceVo.getVr_q(); } else if(fieldName.equals("CIBT")) { fieldValue = vesselPerformanceVo.getCi_by_time_q(); } else if(fieldName.equals("CIBM")) { fieldValue = vesselPerformanceVo.getCi_by_move_q(); } else if(fieldName.equals("TNCT")) { fieldValue = vesselPerformanceVo.getNet_crane_time_q(); } else if(fieldName.equals("TCT")) { fieldValue = vesselPerformanceVo.getCrane_time_q(); } else if(fieldName.equals("TGCT")) { fieldValue = vesselPerformanceVo.getGross_crane_time_q(); } else if(fieldName.equals("TAR")) { fieldValue = vesselPerformanceVo.getTurnaround_rate_q(); } else if(fieldName.equals("CCRCB")) { fieldValue = vesselPerformanceVo.getCcr_q(); } else if(fieldName.equals("CCAAB")) { fieldValue = vesselPerformanceVo.getConsolidated_ccr_q(); } else if(fieldName.equals("CCN")) { fieldValue = vesselPerformanceVo.getControl_qc_m(); } else if(fieldName.equals("CCET")) { fieldValue = vesselPerformanceVo.getControl_qc_end_dt(); } else if(fieldName.equals("LCR")) { fieldValue = vesselPerformanceVo.getLast_cr_q(); } else if(fieldName.equals("LCN")) { fieldValue = vesselPerformanceVo.getLast_qc_m(); } else if(fieldName.equals("VVC")) { fieldValue = vesselPerformanceVo.getVv_c(); } else if(fieldName.equals("OTSSYNCDT")) { fieldValue = vesselPerformanceVo.getOTS_SYNC_DT(); } else if(fieldName.equals("COL")) { fieldValue = vesselPerformanceVo.getCol(); } else if(fieldName.equals("COD")) { fieldValue = vesselPerformanceVo.getCod(); } else if(fieldName.equals("VESMSG")) { if(vesselPerformanceVo.getVesselMessage() != null && vesselPerformanceVo.getVesselMessage().equals("YES")){ String vesselMessage = CPropertiesFactory.getString("OTS.OtsMessages", "QcanReport"); fieldValue = vesselMessage; }else if(vesselPerformanceVo.getVesselMessage() != null && vesselPerformanceVo.getVesselMessage().equals("NO")){ fieldValue = ""; } } else if(fieldName.equals("ListOperationTimeAnalysis")) { fieldValue = new OperationAnalysisDataSource(vesselPerformanceVo.getOperationAnalysisTotalVo()); } else if(fieldName.equals("ListContainer2040Analysis")) { fieldValue = new Container2040AnalysisDataSource(vesselPerformanceVo.getContainer2040ThroughputVo()); } else if(fieldName.equals("ListContainer4548Analysis")) { fieldValue = new Container4548AnalysisDataSource(vesselPerformanceVo.getContainer4548ThroughputVo()); } else if(fieldName.equals("ListMarshallingAnalysis")) { fieldValue = new MarshallingAnalysisDataSource(vesselPerformanceVo.getMarshallingAnalysisList()); } else if(fieldName.equals("ListNonProductiveAnalysis")) { fieldValue = new NonProductiveAnalysisDataSource(vesselPerformanceVo.getNonProductiveAnalysisList()); } } catch(Exception exception) { logger.error("Exception caught in getFieldValue() of QcanDataSource ", exception); } return fieldValue; } } Please help us to solve this issue. Thanks in advance, Sheela ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ jasperreports-questions mailing list jasperreports-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jasperreports-questions