JasperReports + subreports für Anfängern

Atlantis

Grünschnabel
Hallo,

ich sollte mich zur zeit bei JasperReports ein wenig einarbeiten und habe Probleme bei den Subreports.

Eine normale Reports habe ich schon geschafft zu erzeugen, aber nur wie binde ich zum Beispiel zwei Reports in einen Master Report ein?
(habe schon versucht und gesucht habe aber kein idee...)

Weiß jemand wo ich Beispiele finden kann oder kann mir jemand anhand von einfachen beispiele das erklären?

Ich bedanke mich schon mal in vorraus
Schöne Grüße
Atlantis
 
Hallo,

irgendwo im MasterLayout.jrxml muss ein Verweis auf Deinen Subreport stehen

z.B.
### MASTER ###
Code:
<subreport  isUsingCache="true">
	<reportElement
		x="387"
		y="22"
		width="145"
		height="67"
		key="subreport-1"/>
	<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
	<subreportExpression  class="java.lang.String"><![CDATA["C:\\templates\\Firmendaten.jasper"]]></subreportExpression>
</subreport>
### ENDE MASTER ###

Dein Supreport (hier Firmendaten.jrxml) muss vor der Ausführung in ein .jasper compiliert werden. Dies brauchst Du nur 1x zu machen, bzw. immer dann, wenn sich was am Layout deines Report ändert.
Code:
        try {
            JasperCompileManager.compileReportToFile("c:/templates/Firmendaten.jrxml",
                    "c:/templates/Firmendaten.jasper"); 
        } catch (JRException ex) {
            ex.printStackTrace();
        }

Der Aufruf sieht dann folgendermaßen aus:
Code:
            JasperReport jasperReport = JasperCompileManager.compileReport("c:\\templates\\MasterLayout.jrxml");

            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(),sSConnection.getConnection());
 
Hallo,

danke für die Antworten =)
habe es versucht, nur irgendwie zeigt es immer noch nix an :-/

Sagen wir mal, ich habe einen Subreport, das allein Funktioniert und wo ich ein JRDataSoucre Objekt übergebe.

Beispiel:
Code:
JRDataSource daten = new JRBeanCollectionDataSource(list);

JasperReport subReport1 = JasperCompileManager.compileReport("reports/subReport1.jrxml");

JasperPrint jasperPrint = JasperFillManager.fillReport(subReport1, new HashMap(), daten );
JasperViewer.viewReport(jasperPrint, false);

Wie binde ich diese Report in eine Master Report ein?

Habe das wie oben von beschrieben, von Ansatz her und auf verschiedene Wege versucht, aber leider noch nicht erfolgreich gewesen.

Ich bedanke mich schon mal in vorraus
Schöne Grüße
Atlantis
 
Zuletzt bearbeitet:
Hallo,

wie Du einen Report einbindest, habe ich Dir in meinem ersten Posting geschrieben.

Dein Problem an dieser Stelle ist wohl, dass Du mehrere Datenquellen für Deine Reports benutzt und pro Report nur eine Datenquelle zur Verfügung hast.

Eine Möglichkeit wäre also die Daten für Deinen Subreport als Parameter zu übergeben.

Code:
JRDataSource daten = new JRBeanCollectionDataSource(list);

HashMap subDaten = new HashMap();
subDaten.put("sub1",daten);

JasperPrint jasperPrint = JasperFillManager.fillReport(MAINREPORT, subDaten, <DATEN FÜR MAINREPORT");
JasperViewer.viewReport(jasperPrint, false);

Schau Dir doch einfach mal die Samples von Jasperreport -> z.B: subreport und datasource.

Wenn's dann immer noch nicht funktioniert, melde Dich einfach nochmal hier.
 
Hallo Atlantis,

so sollte es funktionieren :

### Main Template -> tutorialsMain.jrxml ###

Code:
<?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="tutorialsMain"
		 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">
	<property name="ireport.scriptlethandling" value="0" />
	<property name="ireport.encoding" value="UTF-8" />
	<import value="java.util.*" />
	<import value="net.sf.jasperreports.engine.*" />
	<import value="net.sf.jasperreports.engine.data.*" />

	<parameter name="DATEN" isForPrompting="false" class="java.lang.Object"></parameter>

	<field name="Nummer" class="java.lang.Integer"/>
	<field name="Kundennummer" class="java.lang.Integer"/>
	<field name="Pos" class="java.lang.Integer"/>
	<field name="Artikelnummer" class="java.lang.String"/>
	<field name="Langtext" class="java.lang.String"/>
	<field name="Nettopreis" class="java.lang.Double"/>
	<field name="Anzahl" class="java.lang.Integer"/>
	<field name="Typ" class="java.lang.Integer"/>
	<field name="id" class="java.lang.Integer"/>
	<field name="Gesamt" class="java.lang.Double"/>
	<field name="MwSt" class="java.lang.Integer"/>
	<field name="GesamtNetto" class="java.lang.Double"/>

		<background>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</background>
		<title>
			<band height="50"  isSplitAllowed="true" >
				<staticText>
					<reportElement
						x="61"
						y="5"
						width="412"
						height="40"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="staticText"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center">
						<font size="30"/>
					</textElement>
				<text><![CDATA[Tutorials.de Jasper Test]]></text>
				</staticText>
				<line direction="TopDown">
					<reportElement
						x="0"
						y="48"
						width="534"
						height="0"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<line direction="TopDown">
					<reportElement
						x="0"
						y="3"
						width="534"
						height="0"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
			</band>
		</title>
		<pageHeader>
			<band height="34"  isSplitAllowed="true" >
				<line direction="BottomUp">
					<reportElement
						x="0"
						y="9"
						width="535"
						height="0"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
			</band>
		</pageHeader>
		<columnHeader>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnHeader>
		<detail>
			<band height="146"  isSplitAllowed="true" >
				<subreport  isUsingCache="true">
					<reportElement
						x="1"
						y="19"
						width="411"
						height="97"
						key="subreport-1"/>
					<subreportParameter  name="ReportTitle">
						<subreportParameterExpression><![CDATA["SubReport"]]></subreportParameterExpression>
					</subreportParameter>
					<subreportParameter  name="DataFile">
						<subreportParameterExpression><![CDATA["c:\\templates\\DataSourceReport.jasper"]]></subreportParameterExpression>
					</subreportParameter>
					<dataSourceExpression><![CDATA[$P{DATEN}]]></dataSourceExpression>
					<subreportExpression  class="java.lang.String"><![CDATA["C:\\templates\\DataSourceReport.jasper"]]></subreportExpression>
				</subreport>
			</band>
		</detail>
		<columnFooter>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnFooter>
		<pageFooter>
			<band height="27"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="325"
						y="4"
						width="170"
						height="19"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font size="10"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["Page " + $V{PAGE_NUMBER} + " of "]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="499"
						y="4"
						width="36"
						height="19"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font size="10"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="1"
						y="6"
						width="209"
						height="19"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font size="10"/>
					</textElement>
				<textFieldExpression   class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
				</textField>
			</band>
		</pageFooter>
		<summary>
			<band height="22"  isSplitAllowed="true" >
			</band>
		</summary>
</jasperReport>
### Ende Main Template ###


### Sub Report -> DataSourceReport.jrxml ###
Code:
<?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="DataSourceReport"
		 columnCount="1"
		 printOrder="Vertical"
		 orientation="Portrait"
		 pageWidth="595"
		 pageHeight="842"
		 columnWidth="515"
		 columnSpacing="0"
		 leftMargin="40"
		 rightMargin="40"
		 topMargin="50"
		 bottomMargin="50"
		 whenNoDataType="NoPages"
		 isTitleNewPage="false"
		 isSummaryNewPage="false">
	<property name="ireport.scriptlethandling" value="0" />
	<property name="ireport.encoding" value="UTF-8" />
	<import value="java.util.*" />
	<import value="net.sf.jasperreports.engine.*" />
	<import value="net.sf.jasperreports.engine.data.*" />

	<style 
		name="Arial_Normal"
		isDefault="true"
		fontName="Arial"
		fontSize="12"
		isBold="false"
		isItalic="false"
		isUnderline="false"
		isStrikeThrough="false"
		pdfFontName="Helvetica"
		pdfEncoding="Cp1252"
		isPdfEmbedded="false"
	/>
	<style 
		name="Arial_Bold"
		isDefault="false"
		fontName="Arial"
		fontSize="12"
		isBold="true"
		isItalic="false"
		isUnderline="false"
		isStrikeThrough="false"
		pdfFontName="Helvetica-Bold"
		pdfEncoding="Cp1252"
		isPdfEmbedded="false"
	/>
	<style 
		name="Arial_Italic"
		isDefault="false"
		fontName="Arial"
		fontSize="12"
		isBold="false"
		isItalic="true"
		isUnderline="false"
		isStrikeThrough="false"
		pdfFontName="Helvetica-Oblique"
		pdfEncoding="Cp1252"
		isPdfEmbedded="false"
	/>

	<subDataset name="SubDataset1" >


	</subDataset>

	<parameter name="ReportTitle" isForPrompting="false" class="java.lang.String">
		<defaultValueExpression ><![CDATA["TEST"]]></defaultValueExpression>
	</parameter>
	<parameter name="DataFile" isForPrompting="false" class="java.lang.String">
		<defaultValueExpression ><![CDATA["DataSourceReport.jasper"]]></defaultValueExpression>
	</parameter>
	<parameter name="DATEN" isForPrompting="false" class="java.lang.Object">
		<defaultValueExpression ><![CDATA[new CustomDataSource()]]></defaultValueExpression>
	</parameter>

	<field name="id" class="java.lang.Integer"/>
	<field name="name" class="java.lang.String"/>
	<field name="street" class="java.lang.String"/>
	<field name="the_city" class="java.lang.String">
		<fieldDescription><![CDATA[me.me.city]]></fieldDescription>
	</field>

	<variable name="CityNumber" class="java.lang.Integer" resetType="Report" incrementType="Group" incrementGroup="CityGroup" calculation="Count">
		<variableExpression><![CDATA[Boolean.TRUE]]></variableExpression>
	</variable>

		<group  name="CityGroup" minHeightToStartNewPage="60" >
			<groupExpression><![CDATA[$F{the_city}]]></groupExpression>
			<groupHeader>
			<band height="20"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Group" evaluationGroup="CityGroup"  hyperlinkType="None"  hyperlinkTarget="Self"  bookmarkLevel="1" >
					<reportElement
						style="Arial_Bold"
						mode="Opaque"
						x="0"
						y="5"
						width="515"
						height="15"
						backcolor="#C0C0C0"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" leftPadding="10" rightBorder="None" rightBorderColor="#000000" bottomBorder="1Point" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["  " + String.valueOf($V{CityNumber}) + ". " + String.valueOf($F{the_city})]]></textFieldExpression>
					<anchorNameExpression><![CDATA[String.valueOf($F{the_city})]]></anchorNameExpression>
				</textField>
			</band>
			</groupHeader>
			<groupFooter>
			<band height="20"  isSplitAllowed="true" >
				<staticText>
					<reportElement
						style="Arial_Bold"
						x="400"
						y="1"
						width="60"
						height="15"
						key="staticText"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font/>
					</textElement>
				<text><![CDATA[Count :]]></text>
				</staticText>
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						style="Arial_Bold"
						x="460"
						y="1"
						width="30"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.Integer"><![CDATA[$V{CityGroup_COUNT}]]></textFieldExpression>
				</textField>
			</band>
			</groupFooter>
		</group>
		<background>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</background>
		<title>
			<band height="70"  isSplitAllowed="true" >
				<line direction="TopDown">
					<reportElement
						x="0"
						y="0"
						width="515"
						height="1"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<textField isStretchWithOverflow="false" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self"  bookmarkLevel="1" >
					<reportElement
						style="Arial_Normal"
						x="0"
						y="10"
						width="515"
						height="30"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center">
						<font size="22"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression>
					<anchorNameExpression><![CDATA["Title"]]></anchorNameExpression>
				</textField>
				<textField isStretchWithOverflow="false" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						style="Arial_Normal"
						x="0"
						y="40"
						width="515"
						height="20"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center">
						<font size="14"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[$P{DataFile}]]></textFieldExpression>
				</textField>
			</band>
		</title>
		<pageHeader>
			<band height="20"  isSplitAllowed="true" >
				<rectangle>
					<reportElement
						x="0"
						y="5"
						width="515"
						height="15"
						forecolor="#333333"
						backcolor="#333333"
						key="rectangle"/>
					<graphicElement stretchType="NoStretch"/>
				</rectangle>
				<staticText>
					<reportElement
						style="Arial_Bold"
						mode="Opaque"
						x="0"
						y="5"
						width="55"
						height="15"
						forecolor="#FFFFFF"
						backcolor="#333333"
						key="staticText"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center">
						<font/>
					</textElement>
				<text><![CDATA[ID]]></text>
				</staticText>
				<staticText>
					<reportElement
						style="Arial_Bold"
						mode="Opaque"
						x="55"
						y="5"
						width="205"
						height="15"
						forecolor="#FFFFFF"
						backcolor="#333333"
						key="staticText"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<text><![CDATA[Name]]></text>
				</staticText>
				<staticText>
					<reportElement
						style="Arial_Bold"
						mode="Opaque"
						x="260"
						y="5"
						width="255"
						height="15"
						forecolor="#FFFFFF"
						backcolor="#333333"
						key="staticText"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<text><![CDATA[Street]]></text>
				</staticText>
			</band>
		</pageHeader>
		<columnHeader>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnHeader>
		<detail>
			<band height="15"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self"  bookmarkLevel="2" >
					<reportElement
						x="0"
						y="0"
						width="50"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" leftPadding="10" rightBorder="None" rightBorderColor="#000000" rightPadding="10" bottomBorder="Thin" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.Integer"><![CDATA[$F{id}]]></textFieldExpression>
					<anchorNameExpression><![CDATA[$F{name} + " (" + $F{id} + ")"]]></anchorNameExpression>
				</textField>
				<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="50"
						y="0"
						width="200"
						height="15"
						key="textField"
						positionType="Float"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" leftPadding="10" rightBorder="None" rightBorderColor="#000000" rightPadding="10" bottomBorder="Thin" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="250"
						y="0"
						width="265"
						height="15"
						key="textField"
						positionType="Float"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" leftPadding="10" rightBorder="Thin" rightBorderColor="#000000" rightPadding="10" bottomBorder="Thin" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[$F{street}]]></textFieldExpression>
				</textField>
			</band>
		</detail>
		<columnFooter>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnFooter>
		<pageFooter>
			<band height="40"  isSplitAllowed="true" >
				<line direction="TopDown">
					<reportElement
						x="0"
						y="10"
						width="515"
						height="1"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="200"
						y="20"
						width="80"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="280"
						y="20"
						width="75"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
				</textField>
			</band>
		</pageFooter>
		<lastPageFooter>
			<band height="60"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self"  bookmarkLevel="1" >
					<reportElement
						x="0"
						y="10"
						width="515"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center">
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["There were " + 
					String.valueOf($V{REPORT_COUNT}) + 
					" address records on this report."]]></textFieldExpression>
					<anchorNameExpression><![CDATA["Summary"]]></anchorNameExpression>
				</textField>
				<line direction="TopDown">
					<reportElement
						x="0"
						y="30"
						width="515"
						height="1"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="200"
						y="40"
						width="80"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Right">
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="280"
						y="40"
						width="75"
						height="15"
						key="textField"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
				</textField>
			</band>
		</lastPageFooter>
		<summary>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</summary>
</jasperReport>

### Ende Sub Report ###

### Java Bean -> CustomDataSource ###
Code:
package de.helper;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;


public class CustomDataSource implements JRDataSource
{

	private Object[][] data =
		{
			{"Berne", new Integer(22), "Bill Ott", "250 - 20th Ave."},
			{"Berne", new Integer(9), "James Schneider", "277 Seventh Av."},
			{"Boston", new Integer(32), "Michael Ott", "339 College Av."},
			{"Boston", new Integer(23), "Julia Heiniger", "358 College Av."},
			{"Chicago", new Integer(39), "Mary Karsen", "202 College Av."},
			{"Chicago", new Integer(35), "George Karsen", "412 College Av."},
			{"Chicago", new Integer(11), "Julia White", "412 Upland Pl."},
			{"Dallas", new Integer(47), "Janet Fuller", "445 Upland Pl."},
			{"Dallas", new Integer(43), "Susanne Smith", "2 Upland Pl."},
			{"Dallas", new Integer(40), "Susanne Miller", "440 - 20th Ave."},
			{"Dallas", new Integer(36), "John Steel", "276 Upland Pl."},
			{"Dallas", new Integer(37), "Michael Clancy", "19 Seventh Av."},
			{"Dallas", new Integer(19), "Susanne Heiniger", "86 - 20th Ave."},
			{"Dallas", new Integer(10), "Anne Fuller", "135 Upland Pl."},
			{"Dallas", new Integer(4), "Sylvia Ringer", "365 College Av."},
			{"Dallas", new Integer(0), "Laura Steel", "429 Seventh Av."},
			{"Lyon", new Integer(38), "Andrew Heiniger", "347 College Av."},
			{"Lyon", new Integer(28), "Susanne White", "74 - 20th Ave."},
			{"Lyon", new Integer(17), "Laura Ott", "443 Seventh Av."},
			{"Lyon", new Integer(2), "Anne Miller", "20 Upland Pl."},
			{"New York", new Integer(46), "Andrew May", "172 Seventh Av."},
			{"New York", new Integer(44), "Sylvia Ott", "361 College Av."},
			{"New York", new Integer(41), "Bill King", "546 College Av."},
			{"Oslo", new Integer(45), "Janet May", "396 Seventh Av."},
			{"Oslo", new Integer(42), "Robert Ott", "503 Seventh Av."},
			{"Paris", new Integer(25), "Sylvia Steel", "269 College Av."},
			{"Paris", new Integer(18), "Sylvia Fuller", "158 - 20th Ave."},
			{"Paris", new Integer(5), "Laura Miller", "294 Seventh Av."},
			{"San Francisco", new Integer(48), "Robert White", "549 Seventh Av."},
			{"San Francisco", new Integer(7), "James Peterson", "231 Upland Pl."}
		};

	private int index = -1;
	

	/**
	 *
	 */
	public CustomDataSource()
	{
	}


	/**
	 *
	 */
	public boolean next() throws JRException
	{
		index++;

		return (index < getData().length);
	}


	/**
	 *
	 */
	public Object getFieldValue(JRField field) throws JRException
	{
		Object value = null;
		
		String fieldName = field.getName();
		
		if ("the_city".equals(fieldName))
		{
			value = getData()[index][0];
		}
		else if ("id".equals(fieldName))
		{
			value = getData()[index][1];
		}
		else if ("name".equals(fieldName))
		{
			value = getData()[index][2];
		}
		else if ("street".equals(fieldName))
		{
			value = getData()[index][3];
		}
		
		return value;
	}

    public Object[][] getData() {
        return data;
    }

    public void setData(Object[][] data) {
        this.data = data;
    }


}
### Ende Java Bean ###

### Programmaufruf ###

Code:
        try {

            String file ="c:/templates/";
            
            JasperCompileManager.compileReportToFile(file + "tutorialsMain.jrxml",
                    file + "tutorialsMain.jasper");
            
            Map parameters = new HashMap();
            parameters.put("DATEN", new CustomDataSource());
            
            JasperPrint jasperPrint = JasperFillManager.fillReport(file + "tutorialsMain.jasper", parameters, new JREmptyDataSource(1));
            
            JasperExportManager.exportReportToPdfFile(jasperPrint,"c:/templates/Tutorials.pdf");
            
        } catch (JRException ex) {
            ex.printStackTrace();
        }
### Ende Programmaufruf ###
 
Hallo OliverT,

danke erstmal für Deine Hilfe,
es hat mir auf jedenfall sehr geholfen und hat auch alles prima geklappt :)

Ich weiß jetzt auf jedenfall wie Subreports funktionieren und habe das auch mit mehrere Subreports usw. ausprobiert =)

Ich bin jetzt schon seit ein Tag mit CrossTab am probieren und schauen wie das so läuft unter anwendung mit JRDataSoucre Objekt übergabe.

Nur bis jetzt habe ich noch nicht geschafft, das es mir was Anzeigt.
Ich weiß auch nicht und bin mir auch nicht sicher, wie ich die jrxml und JRDataSoucre Objekt definiere.

Habe mir auch schon die Beispiele für Crosstab (jrxml und CrosstabApp.java) angeschaut, ich verstehe es noch nicht und weiß auch nicht wie ich die JRDataSoucre definiere soll.

Habe auch nach weitere Bespiele gesucht und leider nichts gefunden,
kannst Du mir da vielleicht auch erklären, wie das Funktioniert?

Ich bedanke mich schon mal in vorraus
Schöne Grüße
Atlantis
 
Zuletzt bearbeitet:
Hallo Atlantis, Hallo OliverT,

es scheint, ihr habt viel Ahnung von JasperReport.

Ich bin neu bei JasperReport und bin noch nicht zur Recht gekommen wie ich ne Report mit JasperReport erstellen soll?

ich habe schon JasperServer bei mir installiert und schaue mir die examlpes anaber kann nicht ganz genau sie nachvollziehen wie die funktioniert.

Wie kann ich ne neuen Report erstellen mit meine eigen Datenbank und jrmxl datei? was brauche ich alle

Danke
Aryan
 
Hallo,

schau Dir doch bitte mal iReport an.
Dort kannst Du über den Designer ganz schnell einen Report und die benötigten
Datenquellen erstellen.

Anonsten wurde in diesem Thread ja schon einiges an Beispielen genannt.
Sollten denoch Fragen offen bleiben kannst Du Dich gerne wieder melden.

Viele Grüße
Olli
 
Zurück