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

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?

Related

Table shift to left when one column hide in jasper table?

I am using jasper report and trying to make RTL report. My problem is that when I am hiding my column in table using printWhenExpression based on some condition my table shift to left. I am using below code to hide column in table.
<jr:column width="160" uuid="f9b26e92-337e-4fb9-a091-4a81469c6c49">
<printWhenExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")]]></printWhenExpression>
<jr:columnHeader style="ColumnHeader" height="30" rowSpan="1">
<textField>
<reportElement style="ColumnHeader" x="0" y="0" width="160" height="30" uuid="b4043ada-2580-4602-9262-3791ce3c0807"/>
<textElement>
<font size="8" isBold="true" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$R{target.external.id}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement style="TableTextContent" x="0" y="0" width="160" height="20" isPrintWhenDetailOverflows="true" uuid="9dc36daa-d5e5-417c-831d-ff1b92ef1b79"/>
<textElement>
<font size="8" isBold="false" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{personExternalId}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
is there is any way so that my table should not shift to left when one of its column which is on left in that table is dynamically hide?
If you want to keep the column and does not want text, remove print when condition on column and add it to text expression :
<textFieldExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")?$R{target.external.id} : ""]]></textFieldExpression>

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.

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 set x, y for a textElement in JasperReports depending on if above textElement is empty. And if non-empty show it down to the that textelement

Requirement:
If firstName and lastName is non empty. Show this at x=125, y=3 coordinates.
And show address down to it at x="125" y="26" coordinate. This is working fine.
Problem: If firstName/lastName are empty, Then we need to move the address element up and show it at x=125, y=3 coordinate itself.
This is where I am stuck. Please help me.
Please refer my jrxml file below:
<frame>
<reportElement key="frame-462" positionType="Float" mode="Transparent" x="0" y="50" width="390" height="70"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-844" positionType="Float" mode="Transparent" x="125" y="3" width="264" height="23"
isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[(!$F{firstName}.isEmpty() && !$F{lastName}.isEmpty())]]></printWhenExpression>
</reportElement>
<textElement markup="styled">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression>
<![CDATA[$F{firstName} + "<style pdfFontName='Helvetica-Oblique' size='11'>" + $F{lastName} + "</style>"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-843" mode="Transparent" positionType="Float" x="125" y="26" width="264"
height="42" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
<textElement markup="html">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<staticText>
<reportElement key="staticText-1249" positionType="Float" x="2" y="2" width="108" height="21"
isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Left">
<font fontName="Verdana" size="12" isBold="false" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[ Address:]]></text>
</staticText>
</frame>
You have already set the isRemoveLineWhenBlank attribute, which will remove the empty space left by the textField. However, JasperReports cannot collapse vertical space unless that space is completely clear. If there is another element occupying the same line (in your case the staticText element), the empty space will be preserved. This is a bit like playing Tetris in reverse; You have to get rid of all of the blocks before the line will disappear.
Putting report elements into frames modifies this behaviour slightly. It is only the width of the parent frame that needs to be clear, instead of the width of the whole report. Therefore, by putting your name and address fields into a separate frame, the space occupied by the name field can collapse despite being aligned horizontally with the static text. I have modified your code snippet to demonstrate this:
<frame>
<reportElement key="frame-462" positionType="Float" mode="Transparent" x="0" y="50" width="390" height="70"/>
<frame>
<reportElement x="126" y="0" width="264" height="70"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-844" positionType="Float" mode="Transparent" x="0" y="3" width="264" height="23" isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[(!$F{firstName}.isEmpty() && !$F{lastName}.isEmpty())]]></printWhenExpression>
</reportElement>
<textElement markup="styled">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{firstName} + "<style pdfFontName='Helvetica-Oblique' size='11'>" + $F{lastName} + "</style>"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-843" mode="Transparent" positionType="Float" x="0" y="26" width="264" height="42" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
<textElement markup="html">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
</frame>
<staticText>
<reportElement key="staticText-1249" positionType="Float" x="2" y="2" width="108" height="21" isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Left">
<font fontName="Verdana" size="12" isBold="false" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[ Address:]]></text>
</staticText>
</frame>

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>