2014-12-13 182 views
0

與此掙扎了一週,是的,我感謝以前的帖子在同一主題上略有進展,但不完全。賈斯珀子報告

兩個報告:

Master Report - Contains company info 
Sub Report - Contains 1..* company orders in detail list 

的數據源是從POJO數組列表內置:

主報告:

<parameter name="SUB_REPORT" class="java.lang.Object"/> 
<queryString> 
    <![CDATA[]]> 
</queryString> 
<field name="companyName" class="java.lang.String"> 
    <fieldDescription><![CDATA[companyName]]></fieldDescription> 
</field> 
<field name="companyOrders" class="java.util.List"> 
    <fieldDescription><![CDATA[companyOrders]]></fieldDescription> 
</field> 
<background> 
    <band splitType="Stretch"/> 
</background> 
<pageHeader> 
    <band height="214" splitType="Stretch"> 
    <textField> 
     <reportElement x="415" y="5" width="40" height="14" uuid="f03490b8-4ab1-4d61-a0d6-f43214dd1c1c"/> 
     <textElement> 
     <font isBold="false"/> 
     <paragraph lineSpacing="Single" lineSpacingSize="2.0"/> 
     </textElement> 
     <textFieldExpression><![CDATA["Date:"]]></textFieldExpression> 
    </textField> 
    <textField> 
     <reportElement x="1" y="110" width="99" height="14" uuid="e82847e9-7235-45d6-9eeb-0f5d2fc2622c"/> 
     <textElement> 
     <font isBold="false"/> 
     <paragraph lineSpacing="Single" lineSpacingSize="2.0"/> 
     </textElement> 
     <textFieldExpression><![CDATA["Business Name:"]]></textFieldExpression> 
    </textField>  
    <textField> 
     <reportElement x="113" y="110" width="252" height="15" uuid="68e891b9-cd70-4b65-90f3-b11866446f4a"/> 
     <textFieldExpression><![CDATA[$F{companyName}]]></textFieldExpression> 
    </textField> 
    </band> 
</pageHeader> 
<columnHeader> 
    <band height="17" splitType="Stretch"> 
    <staticText> 
     <reportElement x="0" y="2" width="100" height="15" uuid="309582cb-bde5-4a37-a97b-c9058fc5e184"/> 
     <text><![CDATA[Order Num]]></text> 
    </staticText> 
    <staticText> 
     <reportElement x="110" y="2" width="100" height="15" uuid="a6fb5059-8126-4ae2-be9c-a5d0ed700ef9"/> 
     <text><![CDATA[Order Amount]]></text> 
    </staticText> 
    <staticText> 
     <reportElement x="220" y="2" width="100" height="15" uuid="198d15de-1484-41cc-b2b0-66b8a75c106d"/> 
     <text><![CDATA[Order Date]]></text> 
    </staticText> 
    <staticText> 
     <reportElement x="369" y="2" width="100" height="15" uuid="d142e6aa-0ff5-416f-b367-d639a287aadd"/> 
     <text><![CDATA[Order Paid]]></text> 
    </staticText> 
    </band> 
</columnHeader> 
<detail> 
    <band height="28" splitType="Stretch"> 
    <subreport> 
     <reportElement x="1" y="4" width="468" height="21" uuid="77507436-37c6-4f8e-bc13-3997be8ffbee"/> 
     <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{companyOrders})]]></dataSourceExpression> 
     <subreportExpression><![CDATA[$P{SUB_REPORT}]]></subreportExpression> 
    </subreport> 
    </band> 
</detail> 

子報告:

<field name="orderNum" class="java.lang.Long"> 
    <fieldDescription><![CDATA[orderNum]]></fieldDescription> 
</field> 
<field name="orderTotal" class="java.lang.Double"> 
    <fieldDescription><![CDATA[orderTotal]]></fieldDescription> 
</field> 
<field name="orderDate" class="java.sql.Timestamp"> 
    <fieldDescription><![CDATA[orderDate]]></fieldDescription> 
</field> 
<field name="orderPaid" class="java.lang.Integer"> 
    <fieldDescription><![CDATA[orderPaid]]></fieldDescription> 
</field> 
<background> 
    <band splitType="Stretch"/> 
</background> 
<detail> 
    <band height="24" splitType="Stretch"> 
     <textField> 
      <reportElement x="0" y="3" width="100" height="15" uuid="d356cc51-325b-43c3-ab2d-dc9f5041d3e4"/> 
      <textFieldExpression><![CDATA[$F{orderNum}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement x="110" y="3" width="100" height="15" uuid="d91fd44f-12f9-4c67-aaca-24c7efa6c75c"/> 
      <textFieldExpression><![CDATA[$F{orderTotal}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement x="222" y="3" width="100" height="15" uuid="af910428-2309-4159-ba5e-c29748f00b6f"/> 
      <textFieldExpression><![CDATA[$F{orderDate}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement x="369" y="3" width="100" height="15" uuid="2921437b-8146-41e4-86fa-6b5ec39f4d65"/> 
      <textFieldExpression><![CDATA[$F{orderPaid}]]></textFieldExpression> 
     </textField> 
    </band> 
</detail> 

化java我使用com的代碼樁和打印報告在運行時:

CompanyMapper cm = new CompanyMapper();   
this.company = cm.getCompanyByID((Long) httpRequest.getSession().getAttribute("userCompanyID")); 
List<ACompany> c = new ArrayList<ACompany>(); 
List<AOrder> companyOrders = getOrders(getParameterInt("orderStatus")); 

c.add(this.company); 

String reportFolder = httpRequest.getServletContext().getRealPath("/").replace('\\', '/') + "reports/";   
String invoice = reportFolder + ReportManager.getProperty("orders");    
String orders = reportFolder + ReportManager.getProperty("orderList"); 
File invoiceFile = new File(invoice); 
File orderFile = new File(orders); 
msgHelper = new MessageHelper();   

JasperReport jasperMasterReport = JasperCompileManager.compileReport(invoiceFile.getAbsolutePath()); 
JasperReport jasperSubReport = JasperCompileManager.compileReport(orderFile.getAbsolutePath()); 

Map<String,Object> parameters = new HashMap<String,Object>();      
parameters.put("SUB_REPORT", jasperSubReport); 
parameters.put("SUB_REPORT_DATA", new JRBeanCollectionDataSource(companyOrders)); 

JasperFillManager.fillReport(jasperSubReport, parameters, new JRBeanCollectionDataSource(companyOrders)); 
JasperPrint print = JasperFillManager.fillReport(jasperMasterReport, parameters, new JRBeanCollectionDataSource(c));    

公司信息顯示精細的主報告然而,在細節沒有訂單從子報表打印。當我打印子報表時,有數據(即訂單明細)按預期顯示。我只想在主人的詳細部分傳遞子報表,並且一切都將完美。

+0

這是怎麼回事懸賞?爲什麼我不能只是發佈問題... – 2014-12-13 23:57:57

回答

0

如果你想使用「companyOrders」作爲一個字段在報表中,你必須把它放在你的「ACompany」 POJO,或多或少這樣的:

public class DataBean { 
    private String companyName; 
    private List<AOrder> companyOrders; 
} 
+0

對不起,延遲。這是對的。 – 2015-05-15 03:24:29