2005 IR Help Posted August 22, 2006 Share Posted August 22, 2006 By: Wendy Hsi - whsi subreport not showing up 2004-02-04 08:27 Hi, Our software is currently looking for a reporting tool. And i have been trying out jasper. One of our requirements is to be able to display multiple reports. I have been looking into using subreports. However there are not many examples i can find where i do not use xml to do the design. If anyone have a simple java design that uses a subreport, i would really appreciate it. this is how i am doing it, but no data seem to show up at all. JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("Test3"); jasperDesign.setPageHeight(595); jasperDesign.setPageWidth(842); JRDesignParameter parameter = new JRDesignParameter(); parameter.setName(sub1); parameter.setValueClass(dori.jasper.engine.JasperReport.class); jasperDesign.addParameter(parameter); JRDesignBand band = new JRDesignBand(); band.setHeight(300); band.addElement(getSubreport(sub1)); jasperDesign.setDetail(band); Thanks, Wendy By: Zoltan Rakonczai - raki RE: subreport not showing up 2004-02-06 01:36 <?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="report1" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <parameter name="param1" isForPrompting="true" class="java.lang.String"/> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="50" isSplitAllowed="true" > </band> </title> <pageHeader> <band height="50" isSplitAllowed="true" > </band> </pageHeader> <columnHeader> <band height="30" isSplitAllowed="true" > </band> </columnHeader> <detail> <band height="300" isSplitAllowed="true" > <subreport isUsingCache="true"> <reportElement mode="Opaque" x="35" y="9" width="418" height="260" forecolor="#000000" backcolor="#CCFFCC" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <subreportParameter name="param1"> <subreportParameterExpression><![CDATA[$P{param1}]]></subreportParameterExpression> </subreportParameter> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> <subreportExpression class="java.lang.String"><![CDATA["c:\projects\report\reports\report2.jasper"]]></subreportExpression> </subreport> </band> </detail> <columnFooter> <band height="30" isSplitAllowed="true" > </band> </columnFooter> <pageFooter> <band height="50" isSplitAllowed="true" > </band> </pageFooter> <summary> <band height="50" isSplitAllowed="true" > </band> </summary> </jasperReport> **************************** **************************** **************************** <?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="report2" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="AllSectionsNoDetail" isTitleNewPage="false" isSummaryNewPage="false"> <parameter name="param1" isForPrompting="true" class="java.lang.String"/> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="50" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="124" y="2" width="55" height="34" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[static text TITLE]]></text> </staticText> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Opaque" x="230" y="13" width="216" height="34" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{param1}]]></textFieldExpression> </textField> </band> </title> <pageHeader> <band height="50" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="161" y="12" width="179" height="24" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[static text PAGE HEADER]]></text> </staticText> </band> </pageHeader> <columnHeader> <band height="30" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="118" y="4" width="260" height="22" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[static text COLUMN HEADER]]></text> </staticText> </band> </columnHeader> <detail> <band height="100" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="24" y="28" width="174" height="36" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[static text KOZEPEN]]></text> </staticText> </band> </detail> <columnFooter> <band height="30" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="52" y="5" width="207" height="17" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[C FOOTER]]></text> </staticText> </band> </columnFooter> <pageFooter> <band height="50" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="55" y="15" width="181" height="25" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[PAGE FOOTER]]></text> </staticText> </band> </pageFooter> <summary> <band height="50" isSplitAllowed="true" > <staticText> <reportElement mode="Opaque" x="26" y="15" width="150" height="26" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="SansSerif" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[sUMMARY]]></text> </staticText> </band> </summary> </jasperReport> ******************************** ******************************** ******************************** package report; import java.io.*; import java.util.*; import javax.swing.*; import dori.jasper.engine.*; import dori.jasper.view.*; public class Test1 { public static void main( String[] args ) { try { JasperReport template = JasperManager.loadReport( new FileInputStream( "c:\projects\report\reports\report1.jasper" ) ); HashMap mapa = new HashMap(); mapa.put("ReportTitle", "HELLO MUKODIK"); mapa.put("param_engedelyezesi_szam", "123456"); mapa.put("report1_param1", "R1P1 EZ Egy PARAMETER"); mapa.put("report2_param1", "R2P1 EZ Egy PARAMETER"); mapa.put("param1", "PARAM EGY"); JasperPrint report = JasperManager.fillReport( template, mapa, new JREmptyDataSource() ); JRViewer jrv = new JRViewer( report ); JDialog viewer = new JDialog(); viewer.setTitle( "Viewer" ); viewer.getContentPane().add( jrv ); viewer.pack(); viewer.show(); } catch( Exception ex ) { ex.printStackTrace(); } } } By: Teodor Danciu - teodord RE: subreport not showing up 2004-02-14 13:21 Hi, Make sure you also provide a connection expression or a data source expression for the subreport element that you add to the band. If not, at least make sure the subreport template has dataType="AllSectionNoDetail" to be able to display something even if no data source is provided. The same for the master report. I hope this helps. Teodor Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now