Jump to content
JasperReports Library 7.0 is now available ×

Problem with Subreports


ktrinad

Recommended Posts

By: norbert - norbertp

Problem with Subreports

2004-10-29 05:13

Hi,

 

I have a serious problem putting a SubReport into a Report. When I execute the java file only the content from the Report will be shown. If I change "JasperManager.fillReport(jasperReport, parameters,

new JREmptyDataSource());" to "JasperManager.fillReport(subReport, parameters,

new JREmptyDataSource());"

the content of the subReport is displayed correctly.

 

I would be very thankful for any suggestion.

 

Norbert

 

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

The Java File

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

 

import java.util.HashMap;

import java.util.Map;

 

import net.sf.jasperreports.engine.JREmptyDataSource;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JasperManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.JasperReport;

import net.sf.jasperreports.engine.design.JasperDesign;

import net.sf.jasperreports.view.JasperViewer;

 

public class Displayer {

 

private JasperDesign jasperDesign;

 

private JasperReport jasperReport;

 

private JasperViewer jasperViewer;

 

private JasperPrint jasperPrint;

 

private JasperReport subReport;

 

private JasperDesign subDesign;

 

private Map parameters;

 

public Displayer() {

displayReport();

}

 

public void displayReport() {

try {

// load the subreport first

subDesign = JasperManager.loadXmlDesign("Subreport.jrxml");

subReport = JasperManager.compileReport(subDesign);

// load the report

jasperDesign = JasperManager.loadXmlDesign("Report.jrxml");

jasperReport = JasperManager.compileReport(jasperDesign);

// prepare the parameters

parameters = new HashMap();

parameters.put("Subreport", subReport);

// fill the report with data

jasperPrint = JasperManager.fillReport(jasperReport, parameters,

new JREmptyDataSource());

// display the report

jasperViewer = new JasperViewer(jasperPrint);

jasperViewer.show();

} catch (JRException e) {

e.printStackTrace();

}

}

 

public static void main(String[] args) {

new Displayer();

}

}

 

 

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

The Report

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

 

<?xml version="1.0" encoding="UTF-8"?>

<!-- Created using an evaluation version of JasperAssistant (http://www.jasperassistant.com) -->

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

 

<jasperReport name="Unnamed" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">

<property name="com.jasperassistant.designer.GridWidth" value="12"/>

<property name="com.jasperassistant.designer.GridHeight" value="12"/>

<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>

<property name="com.jasperassistant.designer.Grid" value="false"/>

<parameter name="Subreport" class="java.lang.Object">

</parameter>

<detail>

<band height="600">

<staticText>

<reportElement positionType="Float" x="160" y="63" width="234" height="24">

<printWhenExpression><![CDATA[new Boolean($P{Subreport} instanceof net.sf.jasperreports.engine.JasperReport)]]></printWhenExpression>

</reportElement>

<textElement textAlignment="Center"/>

<text><![CDATA[$P{Subreport} is instanceof JasperReport]]></text>

</staticText>

<staticText>

<reportElement positionType="Float" x="157" y="15" width="240" height="23"/>

<textElement textAlignment="Center">

<font size="16" isBold="true"/>

</textElement>

<text><![CDATA[i'm a report

]]></text>

</staticText>

<subreport isUsingCache="false">

<reportElement positionType="Float" stretchType="RelativeToBandHeight" isPrintRepeatedValues="false" x="5" y="113" width="544" height="377" isRemoveLineWhenBlank="true">

<printWhenExpression><![CDATA[new Boolean($P{Subreport} instanceof net.sf.jasperreports.engine.JasperReport)]]></printWhenExpression>

</reportElement>

<subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{Subreport}]]></subreportExpression>

</subreport>

</band>

</detail>

</jasperReport>

 

 

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

The SubReport *************************************************

<?xml version="1.0" encoding="UTF-8"?>

<!-- Created using an evaluation version of JasperAssistant (http://www.jasperassistant.com) -->

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

 

<jasperReport name="Unnamed" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">

<property name="com.jasperassistant.designer.GridWidth" value="12"/>

<property name="com.jasperassistant.designer.GridHeight" value="12"/>

<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>

<property name="com.jasperassistant.designer.Grid" value="false"/>

<detail>

<band height="100">

<staticText>

<reportElement positionType="Float" x="133" y="22" width="288" height="28"/>

<textElement textAlignment="Center">

<font size="18" isBold="true"/>

</textElement>

<text><![CDATA[And I'm a SubReport]]></text>

</staticText>

</band>

</detail>

</jasperReport>

 

 

By: norbert - norbertp

RE: Problem with Subreports

2004-10-29 06:30

Mh, I think I should have posted this question in the help forum - sorry.

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...