Jump to content
JasperReports Library 7.0 is now available ×

Setting Variables in Reports


Congor

Recommended Posts

This is a simple Question I guess, and i think

ive solved it so far, but i wonder if there isn't

another way for this task.

 

I want to set Text variables from my Java-Application

It is done by a scriplet, right (like in /demo/samples/jcharts) ?

 

Here is the Scriplet:

 

public class OverviewScriptlet extends JRDefaultScriptlet {

 

public void afterReportInit() throws JRScriptletException {

 

...

super.setVariableValue("NameText", "Egon Schmitz");

 

}

 

}

 

And the Variable in the jasper-xml File

 

[CDATA[$V{NameText}]]

 

 

Or is there another way for text variables?

 

Thanks in advance

Yves

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Ok, i just got it by myself

 

so i guess, this is the solution, and my example

before was just for Objects in general...

 

The java code:

 

Map parameters = new HashMap();

parameters.put("ReportTitle", "Address Report");

JasperFillManager.fillReportToFile(fileName, parameters, getConnection());

 

And the jrxml-file:

 

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

 

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

mode="Opaque"

x="0"

y="0"

width="760"

height="60"

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="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="Monospaced" pdfFontName="Courier" size="22" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

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

</textField>

Link to comment
Share on other sites

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