Reputation: 745
How to add comments in JasperReports template file (JRXML). I need to add some comments in each band to describe the functionality of band and also the need to write some comments for sub reports. So how do I add comments to jrxml file?
Upvotes: 9
Views: 14029
Reputation: 1
In older versions of Jasper (0.6.0), I use simply create a parameter named "Comments" and use the parameterDescription to make my comments.
Here, I can add anything I like. My comments can be as long as I want and can span as many rows as I need. I could keep a chronological update history here if I wanted to. It's not as convenient as in-line commenting, but at least I don't have to worry about iReport removing my comments when it compiles.
Upvotes: 0
Reputation: 454
Since iReport 3.7.1 there is an element called Callouts added especially to cater to comments provision.
Go to Window -> Pallete menu in iReport designer. These "Callouts" works like sticky notes in the iReport interface and in the generated XML it looks like this:
<property name="ireport.callouts" value="##Mon Aug 12 18:03:15 MSK 2013\ncallouts.2.text=This is Detail band\ncallouts.1.text=This is Title Band\ncallouts.2.bounds=353,118,150,75\ncallouts.1.bounds=34,17,239,83"/>
In GUI designer (iReport) notes look like:
For more details look at comments in jrxml are erased by iReport post on http://community.jaspersoft.com
Upvotes: 8
Reputation: 22867
In earlier versions of JasperReports (iReport) do not have such built-in opportunities.
For example, we can use the "custom properties" mechanism for solving this issue.
In the sample below I'm showing how to add the property Description for field in iReport.
For band we can add property manually (add line to jrxml file).
The sample of jrxml file with custom properties:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="sample_comments" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0dfb0d3b-8128-4f2d-b12a-9b5edac0f460">
<property name="Desription" value="This is a sample of report with comments. The custom properties are used"/>
<queryString>
<![CDATA[SELECT id, city FROM address]]>
</queryString>
<field name="ID" class="java.lang.Integer">
<property name="Description" value="The identificator"/>
</field>
<field name="CITY" class="java.lang.String"/>
<title>
<band height="79" splitType="Stretch"/>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<property name="Description" value="Column header Band"/>
<staticText>
<reportElement uuid="8c120f11-e5bf-40e1-9234-3bcede068949" x="0" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Id]]></text>
</staticText>
<staticText>
<reportElement uuid="c8c11f63-d12d-4fbf-b146-dc3d95071065" x="100" y="0" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[City]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="402fcbe3-ef31-475b-8d0f-9da66c3a0692" x="0" y="0" width="100" height="20">
<property name="Description" value="Contains the Id field"/>
</reportElement>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="96bd13a6-a90e-46c6-8c43-ca45b2b7db1d" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
It this jrxml file I've added "comment" for field, textField and to the Band.
You can find alternative method in Preserve XML comments in iReport .jrxml files? post
Upvotes: 5