How to prevent repeating data in JasperReports TextField - jasper-reports

I am using JasperReports and have some problem with textField data continue on next page.
I have 3 textField in detail band.
Band splitType="Stretch".
Every textfiled has borders and isPrintWhenDetailOverflows param set "true".
When data in textfield does not fit on page it continues on next. So i need to print other textfileds of same band (because i need to print borders of every textfield)
But isPrintWhenDetailOverflows="true also leads to repeating data in other textfields on second page though their contents fits on first page.
Illustration:

The jasper report documentation says:
isPrintWhenDetailOverflows()
If this is set to true, the element will be reprinted on the next page if the band does not fit in the current page.
So I think it might be a problem. Remove isPrintWhenDetailOverflows="true". The two things isStretchWithOverflow="true" and stretchType="RelativeToTallestObject" are working for me in this case. So your textField will be like:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="cell" stretchType="RelativeToTallestObject" x="266" y="0" width="266" height="15"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Arial" size="9" isBold="false" pdfEncoding="Cp1251" isPdfEmbedded="true"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{structure}]]></textFieldExpression>
</textField>

Related

remove the white space from columnFooter because columnFooter is only shown on the last page on Jasper [duplicate]

I have a report made in iReport. I included a textFieldExpression in the column footer. My problem is that even though the line is blank it still takes up the space of the height of the band and thus sending the rest of fields to another sheet.
The code that I have is the following:
<columnFooter>
<band height="12" splitType="Stretch">
<printWhenExpression><![CDATA[$F{descripcionComentario}!=null]]></printWhenExpression>
<textField>
<reportElement x="42" y="0" width="100" height="12" uuid="5a9cbe9d-486a-4dd4-a865-d421cd7366a6"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{descripcionComentario}]]></textFieldExpression>
</textField>
</band>
</columnFooter>
The columnFooter is not resizable at run time, you need to find another report structure to solve your issue.
The solution often is to use groups where you have access to the groupFooter band.

Jasper Reports subreport text alignment is wrong only when in main report

When I preview my jasper subreport, text is aligned to the right (what I want).
But when it is used in the main report, text is aligned to the left
On both reports, per element styling is used, set in Jasper Studio.
The jrxml per element looks like...
<textElement textAlignment="Right" markup="html">
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{col_1_initials}]]> </textFieldExpression>
The element including the subreport looks like
<band height="161" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<subreport isUsingCache="false" runToBottom="false">
<reportElement x="-20" y="0" width="595" height="161" uuid="4e6fb330-c43f-4d47-b7aa-6884dad63d14"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("weekPairs")]]></dataSourceExpression>
<subreportExpression><![CDATA["weeksubreport.jasper"]]></subreportExpression>
</subreport>
</band>
I'm not using report Style Templates because for a reason I can't diagnose, Jaspersoft Studio crashes instantly trying to assign a style template.
What about the main report ovverides the subreport text-aligment and what would I have to change in the source to fix this?
EDIT
In the report designer->properties of a jrxml file there is a checkbox for "Derive Attributes". I've tried that both on and off, but nothing changed.

How to relocate summaryband in jasperstudio

I am appending the contentn of my table of content like here: Append an In-Report ToC
Now I have my TOC at the summary band. How can I move it to the second page? Is there any better way to create table of content in jasperstudio?
As recommended in coments i used jasper book. The problem is in the table of content i get dots instead of real text which should be there.
but as you can seen in the picture by hovering the mouse on the dots the real text is shown although without page number!
Here is the XML generated with jasperstudio:
<textField evaluationTime="Group" evaluationGroup="id" hyperlinkType="Reference" bookmarkLevel="2">
<reportElement isPrintRepeatedValues="false" x="-4" y="37" width="534" height="20" printWhenGroupChanges="id" uuid="f6d9376f-7106-4292-b491-7229b297ce04"/>
<textElement markup="html"/>
<textFieldExpression><![CDATA[$F{id}.toString()}]]></textFieldExpression>
<anchorNameExpression><![CDATA[$F{id}.toString()]]></anchorNameExpression>
<hyperlinkReferenceExpression><![CDATA[$F{id}.toString()]]></hyperlinkReferenceExpression>
<hyperlinkTooltipExpression><![CDATA[$F{id}.toString()]]></hyperlinkTooltipExpression>
</textField>

Removing trailing 0 xml Ireport

I'm currently having trouble when producing an iReport, when I run the report it's giving me a weight of 29000.0kg but I require just 29000kg. I've tried different formats but I understand it might need changing in XML.
If anyone could point me in the right direction or assist me in changing this please comments
Currently this is the XML code that is against fields:
<textFieldExpression><![CDATA[$F{EquipmentTareWeightKg} +"kg"]]></textFieldExpression>
Any ideas on how to include this?
I've figured this out, it doesn't require hardcoding but merely changed in the properties window within ireport designer, however if you see below, you change the pattern value to remove decimal places:
</textElement>
<textFieldExpression><![CDATA[$F{EquipmentLengthMm} /1000]]></textFieldExpression>
</textField>
<textField pattern="###0" isBlankWhenNull="true">
<reportElement x="399" y="0" width="32" height="20"/>
<textElement>
<font size="12"/>
</textElement>

How to create a multi language report?

I want to create a document, which prints in more than one language, based on the Locale.
I have created 2 resource bundles, one in English and one in Chinese, but I am not sure how to use them.
Here is the sample of how to implement internationalization support for JasperReports.
The main idea is to use special expression $R{} for localizing text and images.
The sample for images:
<image scaleImage="Clip">
<reportElement positionType="Float" x="20" y="20" width="100" height="50"/>
<imageExpression class="java.lang.String"><![CDATA[$R{image.flag}]]></imageExpression>
</image>
The samples for text (the $R{} syntax):
<textField isBlankWhenNull="true">
<reportElement x="20" y="100" width="530" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{sampleString}]]></textFieldExpression>
</textField>
or (the msg() method):
text.message=The program picked up {0} as a random number.
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="20" y="210" width="530" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[msg($R{text.message}, $P{number})]]></textFieldExpression>
</textField>
Since the document generator may be part of your application, you should somewhere have a language selector menu-item, check-box or combo-box which is already preselected.
So, why don't you just add an if statement that reads the Locale, or the needed language before the report generation, and load the appropriate report accordingly to the locale.
This way you will need to keep one jrxml file for every language. It will be fairly easy to just translate the headers and labels manually.
Your data should be already translated in your database, where you have to keep the relevant attribute values multilingual anyway.
You will need to modify the SQL query for the appropriate language, but since the Query is part of your jrxml it will be executed automatically.