Jump to content
JasperReports Library 7.0 is now available ×

Beginner needs help


2005 IR Help

Recommended Posts

By: balteo - balteo75

Beginner needs help

2004-10-21 06:40

Hello,

 

I am a beginner with Jasper and I have problems with parameters, fields and variables. I have read the tutorials and did not find the answer to my question.

 

I have added a parameter (?_1?) in my jasper report and I am trying to compile my .xml into a .jasper and the compiler says it cannot find the parameter. I intended to give jasper the parameter at runtime with the fillreport function.

 

Where do I need to declare the parameter in order to avoid the compile-time problem?

 

Here is the java class that exports the report into a pdf:

 

public class MonTestJasperDeux {

 

public static void main(String[] args) throws Exception {

Map map = new Hashtable();

map.put("_1", "un");

map.put("_2", "deux");

map.put("_3", "trois");

 

List list = new ArrayList();

list.add("toto");

list.add("titi");

 

 

JRDataSource data = new JRBeanCollectionDataSource (list);

 

 

InputStream jasperFile = MonTestJasperDeux.class.getResourceAsStream("JasperReportUn.jasper");

JasperPrint jPrint = JasperFillManager.fillReport(jasperFile, map, data);

JasperExportManager.exportReportToPdfFile(jPrint, "D:\DocsJulienMartin\dev\TestUnJasper\TestJasper\testDeux.pdf");

 

 

 

}

 

}

 

 

Here is my design:

 

 

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

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

<property name="ireport.scriptlethandling" value="2" />

<variable name="list" class="java.lang.String" resetType="Report" calculation="Nothing">

</variable>

<variable name="_1" class="java.lang.String" resetType="Report" calculation="Nothing">

</variable>

<group name="MonGroup" isStartNewColumn="false" isStartNewPage="false" isResetPageNumber="false" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="0" >

<groupExpression><![CDATA[null]]></groupExpression>

<groupHeader>

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

</band>

</groupHeader>

<groupFooter>

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

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

mode="Opaque"

x="237"

y="19"

width="101"

height="74"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$P{_1}]]></textFieldExpression>

</textField>

</band>

</groupFooter>

</group>

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

<staticText>

<reportElement

mode="Opaque"

x="172"

y="55"

width="63"

height="14"

forecolor="#000000"

backcolor="#FFFFFF"

key="staticText-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<text><![CDATA[Mon Texte]]></text>

</staticText>

</band>

</detail>

<columnFooter>

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

</band>

</columnFooter>

<pageFooter>

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

</band>

</pageFooter>

<lastPageFooter>

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

</band>

</lastPageFooter>

<summary>

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

</band>

</summary>

</jasperReport>

 

 

 

 

Thanks in advance,

 

Julien.

 

 

 

 

 

By: Bj - bjkhan

RE: Beginner needs help

2004-10-21 07:16

Hi Julien,

 

In your XMl jasper file your must declare your parameters as <parameter>...</parameter> not as <variable>..</variable>

Variable are used for report local calculation.

 

Try to use an editor (JasperAssistant for eclipse or iReport), it will help you to avoid this kind of mistake.

 

Regards,

 

Benjamin

 

 

 

 

By: macoute - macoute

RE: Beginner needs help

2004-10-21 07:21

Hi Julien,

 

In your Java class you never compile the template in order to

transform jrxml file to jasper file.

Caution, in your template one variable and one parameter have the same name "_1".

 

Regards,

 

Sté°¨ane LAISNE - FRANCE

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