different number format in iReport and Jasper Server - jasper-reports

i created report in iReport, where is text field with format:
new DecimalFormat("#,##0.00").format($F{NUMBER}) + " €"
In iReport result is 1 234,56 €, which is OK. I am in Slovakia and this is ordinary format here.
In Jasper Server is result 1,234.56 € which is not OK.
Other question: There is still Sk (Slovak Crown) set for Slovakia. Is it possible to set it for EUR ?
Could you help me, what to set where ?
Thanks

If you hard-code the format to use comma for the thousands separator, it's not possible that iReport would ignore this. It sounds like you have not done what you think.
But it seems likely that you need to set the JasperReports Server to use a different locale. You could edit this file:
WEB-INF/applicationContext-security.xml
You'll find the locale section. Add what you need for Slovakia. Then you can choose this locale on the login page.
Or it might be helpful to set the locale in Tomcat's startup script (or whatever app server you are using). These Java parameters might solve your problem (of course you won't want en_US... but those are the parameters):
java -Duser.language=en -Duser.region=US

I have an older version of jasperserver deployed in one of my clients and upgrading it would be a bit of a pain. I'm experiencing the same thing with iReport 4.1.1. My locale is pt_BR and I didn't really want to change my server locale.
I've noticed that iReport is smart (or dumb) enough to not add the class attribute to the textFieldExpression class (I am guessing it guesses from the variable/field type). Jasperserver (at least the version I'm using anyway), on the other hand, does not apply the pattern to numbers if you don't specify the class for that expression.
In other words: iReport generates this markup and renders it as expected:
<textField pattern="###,###,##0.00" isBlankWhenNull="true">
<reportElement mode="Transparent" x="1293" y="0" width="92" height="20"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{my_var}]]></textFieldExpression>
</textField>
You can assume that my_var is a BigDecimal. This field does not get rendered correctly in the server, as it simply ignores the pattern (maybe because it assumes all fields are Strings?) unless you specify the expression class for the textFieldExpression:
<textField pattern="###,###,##0.00" isBlankWhenNull="true">
<reportElement mode="Transparent" x="1293" y="0" width="92" height="20"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{my_var}]]></textFieldExpression>
</textField>
Note the class="java.math.BigDecimal" in the second last line. It sucks that I had to manually edit the jrxml file, but at least Jasperserver renders my report properly.

Related

Detail's text field seems to have a characters limit and stops stretching

I have four reports that are basically different formats of the same report and the following problem happens with three of them. I have a text field in the Detail's band that is marked as Stretch with Overflow. The problem is that it seems that it has some kind of characters limit, because with the following text (110 characters):
MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE COMP.
It's only printing:
MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE
As shown in the screen shots:
It's woth noting that when using the "preview" of the JasperStudio, the whole text appears normally for all of them.
Here's the text field's code of one of them. They're basically the same, changing the width, height and position.
<textField isStretchWithOverflow="true">
<reportElement x="26" y="0" width="76" height="10">
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{descricaoProduto}]]></textFieldExpression>
</textField>
I'm using the 6.2.2 version of JasperReports.
EDIT:
I created a gist with a minimal version of the report that the problem happens:
Sample
I'm exporting it to PDF and using Arial as the font (I added a JAR with the Arial font).
Set the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true (in jasperreports.properties or programmatically). See http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.pdf.force.linebreak.policy
The property instructs the PDF exporter to use java.text.BreakIterator to determine where line breaks can occur in texts, which ensures that the line breaks at PDF export time match the breaks uses when the text was measured at report fill time. As a note, this might come with some impact on PDF exporting performance, but it shouldn't be dramatic.

New page shows unwanted indentation in Jasper Reports

I am using Jasper reports to generate a pdf document. The first line of each paragraph is indented. When a paragraph overflows into the next page the first line in the new page is indented, even if it shouldn't be because it is just a continuation from the other page. Here is an example of a paragraph:
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="0" y="60" width="367" height="1">
</reportElement>
<textElement textAlignment="Justified">
<font fontName="Arial" size="12"/>
<paragraph lineSpacing="1_1_2" firstLineIndent="40"/>
</textElement>
<textFieldExpression><![CDATA["This is an extremely long paragraph, so long that it overflows into the next page and gets wrongly indented.\n"]]></textFieldExpression>
</textField>
I know this is not a stack overflow but still it is an overflow problem. Any ideas?
PS: I am desperate, I will consider even the craziest ideas. Sorry, I have no idea why the xml did not keep the readable indented format. It seems that the indent pops up only where you don't want it.

Exclude column header (but keep first) from a Table component on CSV export in Jasper Reports

I know how to exclude column header from a JR report on CSV report.
I need to know how to exclude column header (but keep first) from a Table component on CSV report.
If this is not possible, any suggestion other than ignore pagination is highly appreciated.
By using this property you can keep your first header in your csv export.
net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.3=columnHeader
net.sf.jasperreports.export.csv.exclude.origin.keep.first.report.3=*
You can use any another name if you already using 3 in your jrxml.
One possible solution is to add a key to each of the column Header report Element. (In this case, key="col_header" in the reportElement tag.)
<jr:columnHeader style="table_CH" height="50" rowSpan="1">
<staticText>
<reportElement uuid="0c6dfd58-9df2-4e00-b79e-43a457c7b42e" key="col_header" x="0" y="0" width="90" height="50"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12"/>
</textElement>
<text><![CDATA[ColumnName]]></text>
</staticText>
</jr:columnHeader>
Next, exclude the key when exporting to CSV. (Add this property to the report properties list).
<property name="net.sf.jasperreports.export.csv.exclude.key.col_header"/>
Voila, the column headers are removed in CSV export.
The downside of this approach:
It removes all the column Headers. (net.sf.jasperreports.export.csv.exclude.key.keep.first.col_header does not work).
Adding Key to each column Header is quite laborious.
If it's possible, just move all column headers to the title band and remove the column headers band itself, and it will only print once in your exported CSV.

Export a Date to Excel using jasper

I'm starting to work with Jasper and havea little problem. I want to export a date who is in my DB and export it to excel and save the date format. The Date is saved with Date in the DB.
The error was when i open the excel file with the data exported the date is not with format date but General. But show right with the pattern written in the jrxml.
That's the code I use to excel export. The other part of the jrxml i think is the default one.
<textField isStretchWithOverflow="true" pattern="dd/MM/yyyy" isBlankWhenNull="true" hyperlinkType="None">
<reportElement stretchType="RelativeToBandHeight" x="343" y="0" width="68" height="21"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" isItalic="true" pdfFontName="arial.ttf"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[$F{Date1}]]></textFieldExpression>
</textField>
Anyone know what i'm doing wrong ???
Another, little question:
- In my Eclipse project i use the jasperreports.jar version 3.5 but i handle/modify the .jrxml with iReporter 3.1.1. That's could cause the problem or problems for use different versions ??
Refer : http://jasperreports.sourceforge.net/sample.reference/xlsfeatures/index.html#xlsfeatures
Format patterns are useful when data have to be presented in a
completely readable and meaningful form. To see an example, dates are
often stored as numbers (the number of milliseconds that have passed
since January 1, 1970 00:00:00.000 GMT). But reading such kind of
numbers does not fit our usual representation of a date, with
perfectly delimited year, month and day fields. A format pattern is
absolutely necessary here, to get a meaningful representation of these
numbers. Here comes the pattern attribute of textfields to solve the
problem. For almost all output formats, excepting the Excel ones.
That's because the pattern attribute contains standard Java format
patterns. Unfortunately, not all patterns valid for Java are valid for
Excel too. There are situations where such a pattern should be
translated in order to be recognized in Excel. An older way to realize
this translation is to use the getFormatPatternsMap() exporter setting
at runtime, with the same inconvenient as shown in the Dynamic Sheet
Names section: the need of Java hardcoding. Instead of this, now one
has the possibility to specify the proper format pattern for Excel
right in the report sample, at element level, using the custom
property net.sf.jasperreports.export.xls.pattern To see it in action,
take a look at the current date textfield in the
XlsFeaturesReport.jrxml sample's section:
<textField pattern="EEE, MMM d, yyyy">
<reportElement style="Sans_Bold" mode="Opaque" x="0" y="30" width="515" height="30" forecolor="#000000">
<property name="net.sf.jasperreports.export.xls.pattern" value="ddd, mmm d, yyyy"/>
</reportElement>
...
</textField>
In this case the EEE, MMM d, yyyy pattern, completely valid in Java
but generating unreadable content for Excel, is replaced with the
equivalent ddd, mmm d, yyyy pattern when exporting report to Excel.

Applying colour to the no records found message

I am working with jasper-reports-4.5.0 and spring 3.0.5RELEASE. I am generating the reports in PDF, HTML, and CSV formats. While generating the reports, if there are no matching records in the database I am displaying the message "No Records Found". How can I make the message appear red?
To set the text to red you just need to set the Forecolor of the text. An example No Data Section with red text would be
<noData>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="555" height="20" forecolor="#FF0000"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[There was no data found.]]></text>
</staticText>
</band>
</noData>
The only caveat to this is that when exporting to csv, obviously the text will not be red since that is just a plain text file. It should work for PDF and HTML though.