Jump to content
We've recently updated our Privacy Statement, available here ×

Getting report name from jasperrepots


hq4ever

Recommended Posts

Hello

 

I'm new to jasper and java as a whole.

I would like to know how I can get access to the jasperreport object from within the jrxml file?

 

I would like to print the name I'm giving to the report.

 

 

 

Thank's for your help guys, happy reporting to us all.

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 months later...

Here's a kludge to get the objectname:

 

Make a variable $V{tester}

[initial value expression]

this.getClass().getName().substring(0,this.getClass().getName().lastIndexOf('_'))

 

[Variable Expression]

$V{tester}.substring(0,$V{tester}.lastIndexOf('_'))

 

then drop a textfield onto your report

[textfield expression]

$V{tester}.substring(0,$V{tester}.lastIndexOf('_'))

Link to comment
Share on other sites

Just pass the name in as a parameter, and set the parameter to have a default value of the name you assign to the report.

 

 

Edit: As an example:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created using 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.Grid" value="false"/>
<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>
<property name="com.jasperassistant.designer.GridWidth" value="12"/>
<property name="com.jasperassistant.designer.GridHeight" value="12"/>
<parameter name="REPORT_NAME" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["My Sample Report"]]></defaultValueExpression>
</parameter>
<detail>
<band height="100">
<textField>
<reportElement x="40" y="9" width="132" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{REPORT_NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

 

HTH,

Robin

Post edited by: rsilver@ns.sympatico.ca, at: 2007/12/17 14:21

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