Jump to content
Changes to the Jaspersoft community edition download ×

Setting Variables in Reports


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





Or is there another way for text variables?


Thanks in advance


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










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


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


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