using conditions to print values in ireport - jasper-reports

I am trying to use conditions to print value in table
I have three columns A B C
A is string
B is integer
C is integer
my condition is If column A == "user"
then print value in column B or make it null
($F{A}.equals("USER")?null:$F{B})
this gives type casting error
<jr:column width="15" uuid="733459e9-1ed8-4ce2-a74d-87dc078b1382">
<jr:tableFooter height="29" rowSpan="1"/>
<jr:columnFooter style="table 8_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 8_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="15" height="20" uuid="bd3860a4-999a-4121-a701-3481a4fdf98e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{TOP}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="15" uuid="2e7fa82c-7f28-4af6-a63d-ae468afeea32">
<jr:tableFooter height="29" rowSpan="1"/>
<jr:columnFooter style="table 8_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 8_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="15" height="20" uuid="33707346-9121-4010-8c12-981eb9f4de77">
<printWhenExpression><![CDATA[$F{TOP}.endsWith("NN")?null:$F{COP}]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{COP}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>

$F{TOP}.endsWith("NN")?null:$F{COP} this should not be in the "Print When Expression" field, for this is a boolean expression field: like print when expression if this = that. Like for instance if I never want to see that field I would put 0==1 in the print when expression field. So remove that line from the print when expression field.
You want to put the line in the field itself. So right-click the field TOP (I am assuming this is the field you want to change if it ends with NN) and select Edit Expression and put this line in replacement of $F{TOP}

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>

Extra blank page after page with list

Here is my JRXML On the second page I created a table using the nested list. In Preview in Jaspersoft Studio everything looks good, but after generating PDF on the page where my nested list is, an empty page is added. I have no idea how I can fix this problem.
I tried:
Remove Line When Blank - for lists and fields.
When No Data Type - all options tried and tested.
I have a problem with generating an additional blank page in PDF. Our company system does not support generating reports from subreports to multiple pages. As a workaround, a 43 page printout was created and each page is divided by "Page Break". This works well. My data source is an XML file.
I've tried to solve previously given here in similar problems but it doesn't help.
I don't want to generate this empty page.
Part of nested list code:
<componentElement>
<reportElement x="0" y="240" width="555" height="40" uuid="5a5114e6-f143-4e73-9a70-6aa3285b4d31">
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="a5783264-74e9-43b2-8312-84e805170f06">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/wstxns1:XML/wstxns1:p7_Object/wstxns1:productOrder/wstxns1:items")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="40" width="555">
<textField>
<reportElement style="Table_TD" x="0" y="0" width="185" height="20" uuid="9f67e274-92bc-4a21-8403-d60b4115c5c3">
</reportElement>
<textElement>
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{prospect/name}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Table_TD" x="185" y="0" width="185" height="20" uuid="262d8477-4cdc-47dc-b746-b38793e05757">
</reportElement>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[($F{totalReccuringChargeAmount}!=null)?(new BigDecimal($F{totalReccuringChargeAmount}).setScale(2, BigDecimal.ROUND_HALF_UP)).toString() + " " + $F{totalReccuringChargecurrency}:""]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Table_TD" x="370" y="0" width="185" height="20" uuid="a9aad9d3-9269-427e-b0e7-032f582c44e7">
</reportElement>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{commitmentPeriod[Level0]}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="20" width="555" height="20" isRemoveLineWhenBlank="true" uuid="96c06463-aaa8-4ee9-80be-0110bbc8258c">
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="100d9171-37f5-45fc-b7b8-affe80e508af">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("//wstxns1:items[wstxns1:itemId = '"+$F{itemId}+"']/wstxns1:configuration/wstxns1:prospect/wstxns1:children/wstxns1:items")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="20" width="555">
<textField>
<reportElement style="Table_TD" x="0" y="0" width="185" height="20" uuid="1e3d8870-3a1f-4cd2-923d-ac1547d5805f">
</reportElement>
<textElement>
<font fontName="SansSerif" size="9"/>
</textElement>
<textFieldExpression><![CDATA["--"+$F{prospect/name}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Table_TD" x="185" y="0" width="185" height="20" uuid="8dee85a5-406b-4a81-ab42-1d29ade1ceab">
</reportElement>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="9"/>
</textElement>
<textFieldExpression><![CDATA[($F{totalReccuringChargeAmount}!=null)?(new BigDecimal($F{totalReccuringChargeAmount}).setScale(2, BigDecimal.ROUND_HALF_UP)).toString() + " " + $F{totalReccuringChargecurrency}:""]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Table_TD" x="370" y="0" width="185" height="20" uuid="80044161-2cc9-461d-bb6b-4b7426d9479c">
</reportElement>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{commitmentPeriod[Level1]}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</jr:listContents>
</jr:list>
</componentElement>
<textField>
<reportElement style="Table_TH" positionType="Float" x="185" y="280" width="185" height="30" backcolor="#D9D9D9" uuid="9e550a00-d376-4f3d-859e-9f3ebd875b76">
</reportElement>
<box>
<pen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Top">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[($F{mainOrderTotalAmount}!=null)?(new BigDecimal($F{mainOrderTotalAmount}).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()+" "+$F{mainOrderCurrency}:" "]]></textFieldExpression>
</textField>
<staticText>
<reportElement style="Table_TH" positionType="Float" x="0" y="280" width="185" height="30" backcolor="#D9D9D9" uuid="aa918c59-db11-49ad-8ab1-1e296b8e8b08">
</reportElement>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Total: ]]></text>
</staticText>
<staticText>
<reportElement style="Table_CH" x="0" y="210" width="185" height="30" backcolor="#D9D9D9" uuid="5e3cea42-8937-4876-9ef3-4fef54ae66db">
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Package name]]></text>
</staticText>
<staticText>
<reportElement style="Table_CH" x="185" y="210" width="185" height="30" backcolor="#D9D9D9" uuid="a76bf537-65a0-400f-a75a-b0f03bd88796">
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Monthly charge]]></text>
</staticText>
<staticText>
<reportElement style="Table_CH" x="370" y="210" width="185" height="30" backcolor="#D9D9D9" uuid="6893b476-bcc2-42ab-8078-364f13b6fcf6">
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Contract period]]></text>
</staticText>
<staticText>
<reportElement x="0" y="750" width="555" height="40" uuid="eb235aed-5c5e-4ef3-b9ab-f776e5307aa9">
</reportElement>
<textElement>
<font fontName="SansSerif" size="9"/>
</textElement>
<text><![CDATA[O749504]]></text>
</staticText>
</band>
Any ideas guys? Maybe you need more details?
Maybe this will help you:
Set the split Typ of the detail band to Stretch:
splitType="Stretch"
best wishes
We had a similar problem. If the a list was the last item in the page in same cases a blank page was added.
When we added the whole list to a new band the empty page disappeared.

Jasper Report: appear extra empty column in the end of table column [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am using jaspersoft studio 5.6.0. I created a table in summary band to display data from database. it generate extra empty column in the end of table. can anybody help me on this problem?
result in word:
jrxml
As #Fabio Fantoni said in the comments, you need to make sure that your table width and column width match up.
Your tables widths do not match up with the width of the columns inside them (some by just a single pixel), this is probably causing the issue.
Here are the correct widths, but you should check them and adjust if needed:
First Table: width = 428 px
Second Table: width = 475 px
Third Table: width = 474 px
These changes can be made in JasperSoft Studio without the need of direct editing of the source.
Example
The following is the jrxml for your summary band with the adjusted table widths to match the width of the columns inside the table. Any adjustment to the column sizes will required you to change the widths of the tables.
<summary>
<band height="343">
<staticText>
<reportElement positionType="Float" x="39" y="1" width="241" height="20" uuid="7ba83b4b-6038-4657-ae77-a50396d66cea"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[A. Posisi TKA Baru yang disetujui :]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="39" y="83" width="58" height="20" isPrintWhenDetailOverflows="true" uuid="e6d5218f-5d8d-4521-bad1-0697e09cfa3d"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[B. Daftar ]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="39" y="160" width="58" height="20" isPrintWhenDetailOverflows="true" uuid="f797ef70-f498-40e0-9f35-181c0bf16933"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[C. Daftar]]></text>
</staticText>
<componentElement>
<reportElement key="table 17" style="table 17" positionType="Float" x="39" y="21" width="428" height="57" isPrintWhenDetailOverflows="true" uuid="6fb859a1-5044-47bd-9249-63fa455470aa">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Table Dataset 1" uuid="84090836-d798-43a0-93bc-3cde0db803f2">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{DS1}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="28" uuid="3363640b-30fb-4c36-b1f6-bc0a53cda03d">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="28" height="30" uuid="bd296baa-e9fe-43de-900e-7c71cd341787"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="28" height="20" isPrintWhenDetailOverflows="true" uuid="128b482b-45e2-4f5c-aeaf-87807921e469"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="136" uuid="20b03b70-6219-4d3b-8261-90b28ca98420">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="136" height="30" uuid="4981f674-08fc-473e-8c5b-fef5b708f14d"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Posisi TKA]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="136" height="20" isPrintWhenDetailOverflows="true" uuid="7e868880-19a9-4d1d-be80-b75f7b508427"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{posisiTka}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="67" uuid="0bd520ee-899a-4a09-a728-40b7e0ded152">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="67" height="30" uuid="5db7fe89-668a-47f1-a74d-89845dc000c9"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Dept.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="67" height="20" isPrintWhenDetailOverflows="true" uuid="44c8d21d-f8d0-4728-8270-0655cf9c02bf"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{departemen}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="88" uuid="41258d68-dd01-4e48-b59e-cdf94f31bd4a">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="88" height="30" uuid="b5d619ef-d7df-4ce1-9684-ac667f2123e7"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Periode Penggunaan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="88" height="20" isPrintWhenDetailOverflows="true" uuid="6ace5c77-cebd-480c-994d-31c593dfe1c9"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{periode}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="109" uuid="0923900a-06e1-46b5-9b06-d7cbd97cea32">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="109" height="30" uuid="7dda780f-29a0-44be-a5bf-de7c059c8b1e"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Keterangan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="109" height="20" isPrintWhenDetailOverflows="true" uuid="683f9507-e3dd-4afe-88bf-29df3296186b"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{keterangan}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<componentElement>
<reportElement key="table 17" style="table 17" positionType="Float" x="39" y="103" width="475" height="52" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="5b51d0bf-d1e9-4745-8ade-b69474871a79">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Table Dataset 1" uuid="1c0dad36-2ce8-481d-aa16-738c65ddbcbe">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{DS2}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="28" uuid="3dd2aa48-6001-475e-8084-b71fe13e63ef">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="28" height="30" uuid="cc51c75b-a38f-4142-996b-ccb0e33503d6"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="28" height="20" uuid="46b22f66-15b3-4819-a353-bb147e83f7af"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="136" uuid="a5200240-1b8e-48ff-a898-60de9a6d8956">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="136" height="30" uuid="f6e47ed7-3098-4c7f-a773-02b48b0c66d3"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Posisi TKA]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="136" height="20" isPrintWhenDetailOverflows="true" uuid="64e41021-7e4d-4c7e-80e4-5ba3c2f7073c"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{posisiTka}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="67" uuid="2f7ca895-6e44-4f8d-8b74-01e074514361">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="67" height="30" uuid="60a909a9-e015-4bb5-8ecc-8e6b85b27570"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Dept.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="67" height="20" isPrintWhenDetailOverflows="true" uuid="dc8674f0-f94e-43b7-9d41-2fdde8873095"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{departemen}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="88" uuid="eb28444a-0f7a-4d0d-ae62-c3189cc73503">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="88" height="30" uuid="5cbf811c-eef7-49d0-8137-013b3b5e1a72"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Periode Penggunaan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="88" height="20" isPrintWhenDetailOverflows="true" uuid="db724659-5863-428a-ab7f-4dae8bd04d42"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{periode}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="157" uuid="ac699b7b-c128-4a90-bd72-caddb826c491">
<jr:columnHeader style="table 17_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="157" height="30" uuid="a0debb58-3628-4861-bf81-019f4dd7f638"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Keterangan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 17_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="157" height="20" isPrintWhenDetailOverflows="true" uuid="8b2d4d5a-80a1-4701-bfd5-519fd1c5f733"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{keterangan}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<componentElement>
<reportElement key="table 18" style="table 18" positionType="Float" x="39" y="181" width="474" height="70" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="0f49d051-fe9a-45ee-a5ab-d570a0b3b2e5">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Table Dataset 1" uuid="28d7100b-eb32-4d34-9222-0141bf26b9f3">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{DS3}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="32" uuid="0ab7278c-e13d-4233-9e82-350e39d1d96a">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="32" height="30" uuid="a41722a3-74fd-4e9d-ba1c-70e54eb0576d"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="32" height="20" uuid="e91dfa23-53ba-4252-a23a-c03b72927b76"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="707eacdf-9a63-4142-bd34-6a325b7a9492">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30" uuid="b8eaaa00-e9e6-47e3-a727-6273ed3e572f"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Nama Posisi Sebelumnya]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="90" height="20" isPrintWhenDetailOverflows="true" uuid="996833d4-3fe3-4194-acef-6f8586b758ab"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{posisiSebelumnya}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="107" uuid="dca6e995-3c22-4996-99dd-874fdfab4890">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="107" height="30" uuid="90a99334-9730-4a70-957e-45ae46cf264e"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Perubahan Nama Posisi yang Disetujui]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="107" height="20" isPrintWhenDetailOverflows="true" uuid="ecf7a33f-3b75-4da9-9636-809887e4bfe3"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{posisiTka}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="64" uuid="4cc762f7-ec87-4fc2-b253-ac3035baed61">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="64" height="30" uuid="425a68df-2c74-4e22-8460-2e34707da3c5"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Dept.]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="64" height="20" isPrintWhenDetailOverflows="true" uuid="386e3887-8962-4273-9d43-4843e9c87c03"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{departemen}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="448fb74b-aeff-4e4f-b92c-47718869e67f">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30" uuid="8e8f5ec8-f2d2-4482-aad1-92a69e062f1f"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Periode Penggunaan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="90" height="20" isPrintWhenDetailOverflows="true" uuid="c0739140-feae-4f5e-bc92-5301f819d207"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{periode}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="91" uuid="d574582b-535a-47c6-a2d6-73eab6970a84">
<jr:columnHeader style="table 18_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="91" height="30" uuid="88f0969f-f791-40fd-88f4-5db2df6d2403"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Keterangan]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 18_TD" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="91" height="20" isPrintWhenDetailOverflows="true" uuid="7cd271d1-0b72-41a8-8521-4b2b533924ff"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{keterangan}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" x="100" y="160" width="455" height="20" isPrintWhenDetailOverflows="true" uuid="faf5ca75-b403-4120-bba0-d463876a7ce5"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{terbilangTable3}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="99" y="83" width="456" height="20" isPrintWhenDetailOverflows="true" uuid="64e2c935-dbf3-4d4f-a8c9-7d7b264c3c1c"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{terbilangTable2}]]></textFieldExpression>
</textField>
</band>
</summary>

How do I hide a table column based on its content?

I have a report which contains a table. I would like to hide the columns of that table based on the result set of the query that backs the table. As an example, here is the XML for one of the columns:
<jr:column width="80">
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="30" style="table_CH"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1_header}</textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1}</textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
For some reason, my report is complaining about the printWhenExpression. It claims that $F{Total1_header} does not exist. It does not complain however about the instance of $F{Total1_header} in the textFieldExpression.
I can't figure out why the field is avaiable for the textFieldExpression, but not the printWhenExpression.
Column has 'Column print when' property to hide/show the column by an expression.
Another way to delete columns is to modify the jasper design at runtime, then report compilation and then procees as usually. This method makes it possible to distribute unused width to remaining columns.
Roughly goes like this:
JasperDesign design = ...
JRDesignComponentElement tableElement = (JRDesignComponentElement) design.getTitle().getElementByKey(tableKey);
StandardTable tableComponent = (StandardTable) tableElement.getComponent();
col = tableComponent.getColumns().get(0);
tableComponent.removeColumn(col);
// Then compile the JasperDesign
JasperReport result=JasperCompileManager.compileReport(design);
For future readers
You should use this
<printWhenExpression><![CDATA[$F{Total1_header} != null]]></printWhenExpression>
Instead of
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>

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>