Jump to content
Changes to the Jaspersoft community edition download ×

Can anybody create and use subreport?


2005 IR Help

Recommended Posts

By: Zoltan Rakonczai - raki

Can anybody create and use subreport?

2004-01-29 00:07

Hello,

 

I'm trying to use subreport with iReport 0.2.2 and JasperReport 0.5.1 without any success.

 

I can put the subreport into a main report, I can compile they in order to get the .jasper files but I can't see the subreport where the subreport should be seen while showing the main report. If I set the background of the subreport to blue and show the main report, I can see the blue background of the subreport (so the subreport is there), but there is nothing in in, it is empty.

 

 

I have tried the subreport example found in the demo/samples/subreport folder of jasperreport but it didn't work.

 

Opposite to that, I can edit and show any other kind of report with jasper and ireport so the only thing I need to know, how to create subreport.

 

If anybody knows, give me the example xml files, please.

 

 

 

 

 

 

 

 

By: tim smal - tcs777

RE: Can anybody create and use subreport?

2004-01-29 01:04

>If anybody knows, give me the example xml files, please.

 

I've had some troubles too, but I figured it out. The main things to think about:

Make sure you

1) define a connection for the subreport in your main report.

2) set the correct path for the supreport

 

Here's a snippet of the xml of a subreport definition that works for me:

 

<snip>

<subreport isUsingCache="true">

<reportElement

mode="Transparent"

x="0"

y="0"

width="540"

height="30"

forecolor="#000000"

backcolor="#FFFFFF"

positionType="Float"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="true"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<subreportParameter name="USER_NAME">

<subreportParameterExpression><![CDATA[$P{USER_NAME}]]></subreportParameterExpression>

</subreportParameter>

<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>

<subreportExpression class="java.lang.String"><![CDATA[$P{PATH} + "cv_sub_p1_1.jasper"]]></subreportExpression>

</subreport>

</snip>

 

$P{REPORT_CONNECTION} = the build-in parameter with the main report's connection.

$P{USER_NAME} = a parameter that is needed by my subreport.

$P{PATH} = path to the folder where I store my compiled subreports.

 

 

 

 

By: Zoltan Rakonczai - raki

RE: Can anybody create and use subreport?

2004-01-29 02:36

I have almost the same structure but I don't use your PATH variable but give the path as follows:

 

 

<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>

<subreportExpression class="java.lang.String"><![CDATA["c:\projects\report\reports\report2.jasper"]]></subreportExpression>

 

 

Would you be so kind as to insert the whole xml files of a working example you use?

 

 

 

 

By: Zoltan Rakonczai - raki

RE: Can anybody create and use subreport?

2004-01-29 23:30

I have the solution. My subreport must contain the

 

whenNoDataType="AllSectionsNoDetail"

 

and this way it works.

 

 

 

 

By: tim smal - tcs777

RE: Can anybody create and use subreport?

2004-01-30 00:17

Great work!

I think I couldn't tell you that..

 

 

 

 

By: Zoltan Rakonczai - raki

RE: Can anybody create and use subreport?

2004-01-30 03:02

But unfortunately I have an another problem. So, no I see my subreport in the main report but there is a textfield on the subreport and I can't see that.

 

If I view my subreport, I can see the textfield.

 

 

 

The xml files I use:

 

*

*

*

*

*

********************************

********MAIN REPORT *************

********************************

*

*

*

*

*

 

 

 

<?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="AllSectionsNoDetail"

isTitleNewPage="false"

isSummaryNewPage="false">

<parameter name="report1_param1" isForPrompting="false" class="java.lang.String"/>

<parameter name="report2_param1" isForPrompting="true" class="java.lang.String">

<defaultValueExpression><![CDATA["AAAAAAAAAAA"]]></defaultValueExpression>

</parameter>

<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="542" isSplitAllowed="true" >

<subreport isUsingCache="true">

<reportElement

mode="Opaque"

x="29"

y="16"

width="478"

height="521"

forecolor="#000000"

backcolor="#CCFFCC"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>

<subreportParameter name="report2_param1">

<subreportParameterExpression><![CDATA["sddddfsdfsdf"]]></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>

 

 

 

 

 

*

*

*

*

*

********************************

********SUB REPORT *************

********************************

*

*

*

*

*

 

 

<?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="report2_param1" isForPrompting="false" class="java.lang.String">

<defaultValueExpression><![CDATA["DEFAULT VALUE"]]></defaultValueExpression>

</parameter>

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="50" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="50" isSplitAllowed="true" >

<staticText>

<reportElement

mode="Opaque"

x="388"

y="114"

width="76"

height="23"

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[sTATIC2]]></text>

</staticText>

</band>

</pageHeader>

<columnHeader>

<band height="30" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="100" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="189"

y="32"

width="137"

height="24"

forecolor="#000000"

backcolor="#FF9999"

positionType="FixRelativeToTop"

isPrintRepeatedValues="false"

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{report2_param1}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="30" isSplitAllowed="true" >

<staticText>

<reportElement

mode="Opaque"

x="38"

y="-68"

width="92"

height="19"

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[sTATIC1]]></text>

</staticText>

</band>

</columnFooter>

<pageFooter>

<band height="50" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="50" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

 

*

*

*

*

*

********************************

********JAVA CODE I USE **********

********************************

*

*

*

*

*

 

 

 

JasperReport template = JasperManager.loadReport( new FileInputStream( "c:\projects\report\reports\report1.jasper" ) );

 

HashMap mapa = new HashMap();

 

mapa.put("report2_param1", "R2P1 EZ Egy PARAMETER");

 

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();

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...