Building Jasperreport Textfield message with multiple parameters and types - jasper-reports

Im trying to create a message in a textfield which uses a localized string in a properties file. The string has 5 parameters, 1 string, 2 numbers and 2 dates.
For some reason i get this message when trying to compile it.
The method msg(String, Object) in the type JREvaluator is not applicable for the arguments (String, String, Integer, Integer, Date, Date)
Here is the textfield
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="5c7c4cab-cbd4-4c0b-8393-c3b5ba3bc856" positionType="Float" x="0" y="0" width="530" height="20"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[msg($R{report.title},$P{QUERY_LEGAL_ENTITY_NAME},
$P{QUERY_START_ACCOUNT_NUMBER},
$P{QUERY_END_ACCOUNT_NUMBER},
$P{QUERY_START_DATE},
$P{QUERY_END_DATE}
)]]></textFieldExpression>
</textField>
And here is the properties string
report.title=Finanskonti for {0} | Konti: {1, number} - {2,number} | Datoer: {3,date} - {4,date}
Got any ideas what im doing wrong

I got it working using this code
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="5c7c4cab-cbd4-4c0b-8393-c3b5ba3bc856" positionType="Float" x="0" y="0" width="530" height="20"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[msg($R{report.title}, new Object[]{$P{QUERY_LEGAL_ENTITY_NAME},
$P{QUERY_START_ACCOUNT_NUMBER},
$P{QUERY_END_ACCOUNT_NUMBER},
(new SimpleDateFormat("dd-MM-yyyy")).format($P{QUERY_START_DATE}),
(new SimpleDateFormat("dd-MM-yyyy")).format($P{QUERY_END_DATE})}
)]]></textFieldExpression>
</textField>
hope someone else can use it.

Related

Text Field dynamic height in JasperReports 6.12.2

I'm currently working in a API that will generate reports (with JasperReports 6.12.2), in this case I have to print a large String in a text field, the problem is that I can't give the appropiate behaviour to this element to adjust the height to the String size.
I've been searching before to ask, and all that I've found was about the property isStretchWithOverflow="true", but isn't working for me because in my version this is deprecated and replaced with textAdjust="StretchHeight" so basically all the results finish with the same, the text is cutted by the text field.
Note: Also I have to say that this necessity of dynamism is because i need to paginate the report.
Element Text Field JRXML code:
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="190" width="555" height="321" isPrintWhenDetailOverflows="true"/>
<textFieldExpression><![CDATA[$P{text}]]></textFieldExpression>
</textField>
Complete Band Detail JRXML code:
<detail>
<band height="802" splitType="Stretch">
<textField>
<reportElement x="0" y="40" width="140" height="20" uuid="8e0ef27f-45c4-45f5-8c36-93e126db95db"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.codigo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="140" height="20" uuid="6cfe8e0b-0b7d-47f5-be4e-4c94d7f19fac"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.fecha}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="80" width="140" height="20" uuid="c8508fc6-3b17-4bcc-a207-2a9beff32263"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.enviado}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="100" width="140" height="20" uuid="5f7c732e-aeee-4896-bf11-dbd8f2c2b02f"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.asunto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="120" width="140" height="20" uuid="71f51ac1-63c5-4abb-909a-3f31b14e0e80"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.canal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="140" width="140" height="20" uuid="00e9ac8d-c331-429d-944a-240e6abf2107"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.nombre}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="140" height="20" uuid="4b22fdfb-36a3-41da-86d1-a527ca67667d"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.texto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="40" width="405" height="20" uuid="bc346e06-c225-4451-bde7-67bde39d402e"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{codigo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="60" width="405" height="20" uuid="1d0ac2a4-fcb9-4ad3-9d9d-db440ae5cfb3"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format( new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse($P{fAlta}))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="80" width="405" height="20" uuid="d0189a13-4ded-45a1-82ad-5896a50f7fbf"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{mailPara}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="100" width="405" height="20" uuid="b0cfff7f-9230-4351-a59c-bf550fc4f0c2"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{asunto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="140" width="405" height="20" uuid="15f48c57-404d-47e2-94a9-26da75054aa9"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{operador}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="150" y="120" width="405" height="20" uuid="0926440c-f596-47a4-b7b4-674faa82b407"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<text><![CDATA[Operador ATC]]></text>
</staticText>
<textField>
<reportElement x="0" y="20" width="140" height="20" uuid="664930ad-64a1-44fc-9cdb-4ef34eb7cffa"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.idPeticionATC}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="20" width="405" height="20" uuid="d9303c25-1ea8-45ca-b4b7-984a0b95d4ee"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{idPeticionATC}]]></textFieldExpression>
</textField>
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="190" width="555" height="321" isPrintWhenDetailOverflows="true" uuid="0e59dd92-0a62-453a-9167-6a9d5b43ff54"/>
<textFieldExpression><![CDATA[$P{text}]]></textFieldExpression>
</textField>
</band>
After a while trying to solve this issue I've found the problem.
Recently Jasper Reports upgraded the version to v6.11 (Published: 2019-Dec-12), in this version Jaspersoft® Studio changed the property isstretchwithoverflow is replaced by textAdjust, so the problem was related with the version, and I realized that my Jasper reports library was in an older version v6.2, where the propertie textAdjust doesn't even exist.
So if anyone else is having this problem, please, check your library version, if it's under version 6.11 and your editor plugin is version 6.11 or higher, you will not be able to overflow texts and paginate properly.
The property isStretchWithOverflow was replaced in the JasperReports Library 6.10.0 by the textAdjust property. So to achieve the dynamic stretching effect, you need to set textAdjust="StretchHeight".
If you set your compatibility settings in Jaspersoft Studio ("Window > Preferences > Jaspersoft Studio > Compatibility") accordingly, it will automatically change the property to the compatible version, i.e. textAdjust="StretchHeight" will automatically be exchanged for isStretchWithOverflow="true" when you select a version <= JasperReports 6.5.1.

How to combine two textFields into one box in RTF generated by Jasper reports?

I use Jasper Reports to generate RTF file.
In RTF each textField is represented as separate box:
I tried to use one frame for textFields:
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="220" y="45" width="406" height="75"/>
<textField>
<reportElement positionType="Float" x="0" y="0" width="406" height="60"/>
<textElement>
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA["Address:"]]></textFieldExpression>
</textField>
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement x="0" y="57" width="200" height="15" key="textWithStyle" style="LinkField"/>
<textElement>
<font fontName="Arial" size="8" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA["here"]]></textFieldExpression>
<hyperlinkReferenceExpression><![CDATA["http:adress"]]></hyperlinkReferenceExpression>
</textField>
</frame>
But textFields also in the different boxes.
Is it possible to combine several textFields into one box like the following?
I know that I can add each text to one textField, but sometimes I need two separate textFields that I can manage inside one box.

Jasper: collapse white space when string element is empty [duplicate]

This question already has answers here:
How to get rid of this band line in report
(1 answer)
How to remove frame with empty textFields?
(1 answer)
How to use positionType to pull a component up when the above component is not displayed in jasper?
(1 answer)
Closed 3 years ago.
I need to collapse a field when it's null or empty.
I have this jrxml source code
<textField>
<reportElement x="180" y="0" width="200" height="20" uuid="5d7e1430-4275-4c04-a609-b12adf976cd2"/>
<textElement markup="styled">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="false">
<reportElement positionType="Float" x="180" y="20" width="200" height="20" isRemoveLineWhenBlank="true" uuid="3e10e11d-131e-4059-b885-0210e651b5bd">
<printWhenExpression><![CDATA[$F{vote} != null && !$F{vote}.equals("")]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Proportional"/>
</textElement>
<textFieldExpression><![CDATA["Voto: "+$F{vote}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="40" width="200" height="30" uuid="2623f12e-a68f-4173-8f64-69a54ce50a0a"/>
<textFieldExpression><![CDATA[$F{organisationName}]]></textFieldExpression>
</textField>
The Field Vote sometimes is empty or null and with $F{vote} != null && !$F{vote}.equals("")] it isn't displayed, but the space remain white and it doesn't disappear.
This is my result
This is what I want
Where am I wrong?

Check if is null JasperReports

I have the following problem with JasperReports , I receive the content correctly , however when the content is null i am interesting to not showing nothing.
Could anyone help to me?
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement/>
<textFieldExpression><![CDATA[$F{nombre}]]></textFieldExpression>
</textField>
Set "blank when null" checkbox at property of field
After that definition text filed in jrxml like this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
....
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="DejaVu Sans" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{leftColumn}]]></textFieldExpression>
</textField>

How to display page x of y in my jasper report

I am generating the reports using jasperreport-4.5.0.It is generating the report properly.But if i have huge data in my database then the report vl display in different pages.So my requirement is if my report has 12 pages then i want to display page 1 of 12,page 2 of 12,page 3 of 12....like this in my page header band.How can i do this can any one give an idea regarding this.
You can use the evaluationTime="Report" attribute to achieve this.
Consider the following example, we first print "PAGE" then we print the page number using the default evalutaionTime attribute. This will print the current page number, then we print OF and finally the page number with evaluation time set to "report" which will print the total number of pages.
<band height="20">
<elementGroup>
<textField>
<reportElement positionType="FixRelativeToBottom" x="709" y="0" width="53" height="20"/>
<textElement verticalAlignment="Top">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA["PAGE"]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="FixRelativeToBottom" x="762" y="0" width="23" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="FixRelativeToBottom" x="785" y="0" width="29" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA["OF"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement positionType="FixRelativeToBottom" x="814" y="0" width="26" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</elementGroup>
</band>