JasperReport - condition in TextElement - jasper-reports

I'm new at JasperReports.
I want to get italic text when some variable will be set at '3'.
Here's my code:
<textElement>
<font size="9" pdfFontName="Helvetica" pdfEncoding="Cp1250" isPdfEmbedded="true"
isItalic=<![CDATA[$F{variable}==3 ? "true" : "false"]]> />
</textElement>
What am I doing wrong?
I tried also make conditional style but wherever I put i recive error.

You cannot use set value of the property isItalic (and many others) with help of expressions.
In your case you should use the conditional style.
The sample:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
<style name="customStyle">
<conditionalStyle>
<conditionExpression><![CDATA[$F{variable} == 3]]></conditionExpression>
<style isItalic="true"/>
</conditionalStyle>
</style>
...
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement style="customStyle" mode="Opaque" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

Related

Conditional Formatting according to value in Jasper Reports

I would like to know if there's a way to re-use conditional formatting for several textFields each one associated to different parameters.
Right now I´ve manage to do it by writing a custom style for each one, but it´s a nightmare to mantain.
Here´s what I´ve got:
<style name="style_door" mode="Transparent" forecolor="#000000">
<conditionalStyle>
<conditionExpression><![CDATA[$P{door}.equals("REPLACE")]]></conditionExpression>
<style mode="Transparent" forecolor="#CC0000"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$P{door}.equals("REPAIR")]]></conditionExpression>
<style mode="Transparent" forecolor="#FF9900"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$P{door}.equals("OK")]]></conditionExpression>
<style mode="Transparent" forecolor="#009900"/>
</conditionalStyle>
</style>
<style name="style_window" mode="Transparent" forecolor="#000000">
<conditionalStyle>
<conditionExpression><![CDATA[$P{window}.equals("REPLACE")]]></conditionExpression>
<style mode="Transparent" forecolor="#CC0000"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$P{window}.equals("REPAIR")]]></conditionExpression>
<style mode="Transparent" forecolor="#FF9900"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$P{window}.equals("OK")]]></conditionExpression>
<style mode="Transparent" forecolor="#009900"/>
</conditionalStyle>
</style>
<textField>
<reportElement style="style_door" x="112" y="26" width="53" height="13" uuid="07eacbda-9ed8-418e-9f97-937bb44ca976"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$P{door}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="style_window" x="112" y="26" width="53" height="13" uuid="07eacbda-9ed8-418e-9f97-937bb44ca976"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$P{window}]]></textFieldExpression>
</textField>
Notice that the 2 styles are the same, it just change the condition, because it should match a different parameter. And then I apply the style to each textField.
Is there a way I can write a single style and the condition be matched with the value of the element associated to? Or could I pass the element's value as an argument to the style and be used in the condition?
Thank you!
Here is a answer to a similar question from a while back.
I've done some testing and contradictory to the answer linked above I managed to do it without a additional class. All other statements, especially regarding evaluation time and style.evaluation.time still apply. Please read the explanations linked in the answer above.
Example for your application:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.1.1 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Apply style withou name" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c7e9565b-28fb-4eeb-b6e0-cd9bd8460722">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter"/>
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
<style name="ColoredText">
<conditionalStyle>
<conditionExpression><![CDATA[((String)$V{STORAGE}.get("key")).equals("OK")]]></conditionExpression>
<style forecolor="#009900"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[((String)$V{STORAGE}.get("key")).equals("REPAIR")]]></conditionExpression>
<style forecolor="#FF9900"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[((String)$V{STORAGE}.get("key")).equals("REPLACE")]]></conditionExpression>
<style forecolor="#CC0000"/>
</conditionalStyle>
</style>
<parameter name="door" class="java.lang.String"/>
<parameter name="window" class="java.lang.String"/>
<variable name="STORAGE" class="java.util.Map" calculation="System">
<initialValueExpression><![CDATA[new java.util.HashMap()]]></initialValueExpression>
</variable>
<detail>
<band height="21">
<textField evaluationTime="Auto" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="20" uuid="d9392134-e246-41c7-8c66-9d21f06e0465"/>
<textFieldExpression><![CDATA[$V{STORAGE}.put("key", $P{window}) == null ? null : null]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto" isBlankWhenNull="true">
<reportElement style="ColoredText" x="0" y="0" width="100" height="20" uuid="fda2f3f5-fe34-424e-8af9-b4f0111936b2"/>
<textFieldExpression><![CDATA[$V{STORAGE}.get("key")]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto" isBlankWhenNull="true">
<reportElement x="100" y="0" width="100" height="20" uuid="6dcf014e-ffc9-47be-81ee-04f1912d3be2"/>
<textFieldExpression><![CDATA[$V{STORAGE}.put("key", $P{door}) == null ? null : null]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto" isBlankWhenNull="true">
<reportElement style="ColoredText" x="100" y="0" width="100" height="20" uuid="54cc1367-8387-4fc0-be00-5ba789cce7e9"/>
<textFieldExpression><![CDATA[$V{STORAGE}.get("key")]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

How to insert empty row at the table based on condition in case using JRBeanCollectionDataSource?

There is a list and I use this mechanism to pass it to my jasper report:
JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(list);
The Object of that list is as follows:
public class Test{
private int id;
//other properties + getters & setter
}
Now Assume I have 10 elements within my list (id= 1 to 10) and I want to separate them in one table using an empty row, meaning 5 rows top, one empty row, 5 rows down.
How to do that ?
The subreport element can helps with solving this problem - we can show or hide subreport based on condition using printWhenExpression.
In your case we need to show subreport with one empty line.
Example
The subreport for showing empty line is very simple. It does not need datasource for showing data - we can put staticText right at Title band. We don't need also margins.
The jrxml will be:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Empty Line" pageWidth="572" pageHeight="30" whenNoDataType="AllSectionsNoDetail" columnWidth="572" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<style name="bordered">
<box>
<pen lineWidth="0.25"/>
</box>
</style>
<title>
<band height="30" splitType="Stretch">
<staticText>
<reportElement style="bordered" x="0" y="0" width="572" height="30"/>
</staticText>
</band>
</title>
</jasperReport>
I used simple csv datasource for example - file films.csv contains data for report:
id,name,year,rating
1,The Shawshank Redemption,1994,9.3
2,The Godfather,1972,9.2
3,The Dark Knight,2008,9.0
4,The Godfather: Part II,1974,9.0
5,The Lord of the Rings: The Return of the King,2003,8.9
6,Pulp Fiction,1994,8.9
7,Schindler's List,1993,8.9
8,"The Good, the Bad and the Ugly",1966,8.9
9,12 Angry Men,1957,8.9
10,Avengers: Endgame,2019,8.8
The main (master) report is using CSV File Data Adapter for building report.
The jrxml of master report:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Insert blank row on condition" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="films.csv"/>
<style name="bordered">
<box>
<pen lineWidth="0.25"/>
</box>
</style>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<field name="year" class="java.lang.String"/>
<field name="rating" class="java.math.BigDecimal"/>
<title>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="158" y="0" width="256" height="30"/>
<text><![CDATA[Films. Showing empty line for Id == 5]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="70" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Id]]></text>
</staticText>
<staticText>
<reportElement x="70" y="0" width="290" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="69" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Year]]></text>
</staticText>
<staticText>
<reportElement x="429" y="0" width="143" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Rating]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="60">
<subreport>
<reportElement x="0" y="30" width="572" height="30" isRemoveLineWhenBlank="true" >
<printWhenExpression><![CDATA[$F{id} == 5]]></printWhenExpression>
</reportElement>
<subreportExpression><![CDATA["empty_row.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement style="bordered" x="0" y="0" width="70" height="30"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="bordered" x="70" y="0" width="290" height="30"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="bordered" x="360" y="0" width="69" height="30"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{year}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="bordered" x="429" y="0" width="143" height="30"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{rating}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I used <printWhenExpression><![CDATA[$F{id} == 5]]></printWhenExpression> for hiding subreport with empty line, it means that empty line will show only of row with id == 5. You can use any expression you want.
The output at JSS will be:
Alternative solutions
You can insert element during building collection before passing this collection at JRBeanCollectionDataSource.
You can implement custom DataSource based on JRBeanCollectionDataSource with some logic.

How to organize Frames in Jasper Report so they float flawlessly?

In a Jasper report I have 4 Frames (below image) which have some properties set as shown in the same image.
Now, the idea is that given certain parameters showBlue and showRed the frames BLUE and RED respectively are shown or hidden and the subsequent frame "floats" after the previous one (taking in consideration the following order: BLUE <- RED <- GREEN) while BLACK should stay in the same place.
The two left frames (RED and GREEN) were floating up perfectly before the BLACK one was set in place. After that when I set the parameters showBlue and showRed to false (hide BLUE and RED frames) this is the result:
This is the jrxml for the report design:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Float_UP" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6578bc34-0c2e-4179-99da-5ec1dd90a422">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="showBlue" class="java.lang.Boolean"/>
<parameter name="showRed" class="java.lang.Boolean"/>
<queryString>
<![CDATA[]]>
</queryString>
<detail>
<band height="211" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="400" height="12" uuid="54cb1704-59d8-4272-9ec1-db4cea913cd3"/>
<text><![CDATA[Header 1 (right before conditional frame)]]></text>
</staticText>
<frame>
<reportElement x="0" y="15" width="400" height="66" isRemoveLineWhenBlank="true" uuid="0140ba9b-f2f0-494c-82bc-caf6b5efc63e">
<printWhenExpression><![CDATA[$P{showBlue}]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="3.0" lineColor="#2E0DD4"/>
</box>
<staticText>
<reportElement x="1" y="1" width="379" height="59" uuid="a8b7d505-a6ad-4359-9263-23ac087b19ff"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[BLUE: `isRemoveLineWhenBlank=true` and `printWhenExpression` set]]></text>
</staticText>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="85" width="400" height="60" isRemoveLineWhenBlank="true" uuid="c80dd879-ce81-4921-b17e-9882763a3f61">
<printWhenExpression><![CDATA[$P{showRed}]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="3.0" lineColor="#F50A25"/>
</box>
<staticText>
<reportElement x="0" y="0" width="380" height="50" uuid="d0cadbd4-b436-47f4-a32d-2b00f0c6b147"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[RED: `isRemoveLineWhenBlank=true`, `printWhenExpression` set and `positionType="Float"`]]></text>
</staticText>
</frame>
<frame>
<reportElement positionType="Float" x="2" y="151" width="398" height="60" uuid="e0a5ed13-d8f2-4acd-ac14-1f5633099542"/>
<box>
<pen lineWidth="3.0" lineColor="#22B002"/>
</box>
<staticText>
<reportElement x="1" y="1" width="377" height="39" uuid="482471b4-4c3b-42c6-892d-f8c42ca320bf"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[GREEN: `positionType="Float"`]]></text>
</staticText>
</frame>
<frame>
<reportElement x="420" y="15" width="130" height="70" uuid="8e057d80-72be-4f66-ae9b-ef80610daf36"/>
<box>
<pen lineWidth="3.0"/>
</box>
<staticText>
<reportElement x="6" y="6" width="118" height="44" uuid="36d8e560-3af5-4edf-b9ef-9b9311877c3a"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[BLACK]]></text>
</staticText>
</frame>
</band>
</detail>
</jasperReport>
And I have set up a Java Project with Swagger in case you want to run it with maven.
Q: How can I make frames RED and GREEN to properly "float-up" after its previous frame while frame BLACK stays in the same place?
Yes the green will not float up since the black box is placed immediately above it
From JRElement API
Float - The element floats in its parent section if it is pushed downward by other elements found above it. It tries to conserve the distance between it and the neighboring elements placed immediately above it
Solution
The solutions obviously is to not have any element immediately above it and one way to achieve this is to use another frame or a subreport. If you need elements to float up also under this design you probably will need a subreport but I will show the parent frame solution, because it is the easiest way to solve your direct problem.
Example using a parent frame
jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Float_UP" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6578bc34-0c2e-4179-99da-5ec1dd90a422">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="showBlue" class="java.lang.Boolean"/>
<parameter name="showRed" class="java.lang.Boolean"/>
<queryString>
<![CDATA[]]>
</queryString>
<detail>
<band height="96" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="400" height="12" uuid="54cb1704-59d8-4272-9ec1-db4cea913cd3"/>
<text><![CDATA[Header 1 (right before conditional frame)]]></text>
</staticText>
<frame>
<reportElement x="0" y="15" width="409" height="78" uuid="82076f1d-b7a9-4b63-ab4a-af54b0817a62"/>
<frame>
<reportElement x="0" y="4" width="400" height="66" isRemoveLineWhenBlank="true" uuid="0140ba9b-f2f0-494c-82bc-caf6b5efc63e">
<printWhenExpression><![CDATA[$P{showBlue}]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="3.0" lineColor="#2E0DD4"/>
</box>
<staticText>
<reportElement x="1" y="1" width="379" height="59" uuid="a8b7d505-a6ad-4359-9263-23ac087b19ff"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[BLUE: `isRemoveLineWhenBlank=true` and `printWhenExpression` set]]></text>
</staticText>
</frame>
<frame>
<reportElement positionType="Float" x="-1" y="75" width="400" height="60" isRemoveLineWhenBlank="true" uuid="c80dd879-ce81-4921-b17e-9882763a3f61">
<printWhenExpression><![CDATA[$P{showRed}]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="3.0" lineColor="#F50A25"/>
</box>
<staticText>
<reportElement x="0" y="0" width="380" height="50" uuid="d0cadbd4-b436-47f4-a32d-2b00f0c6b147"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[RED: `isRemoveLineWhenBlank=true`, `printWhenExpression` set and `positionType="Float"`]]></text>
</staticText>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="140" width="398" height="60" uuid="e0a5ed13-d8f2-4acd-ac14-1f5633099542"/>
<box>
<pen lineWidth="3.0" lineColor="#22B002"/>
</box>
<staticText>
<reportElement x="1" y="1" width="377" height="39" uuid="482471b4-4c3b-42c6-892d-f8c42ca320bf"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[GREEN: `positionType="Float"`]]></text>
</staticText>
</frame>
</frame>
<frame>
<reportElement x="420" y="15" width="130" height="70" uuid="8e057d80-72be-4f66-ae9b-ef80610daf36"/>
<box>
<pen lineWidth="3.0"/>
</box>
<staticText>
<reportElement x="6" y="6" width="118" height="44" uuid="36d8e560-3af5-4edf-b9ef-9b9311877c3a"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[BLACK]]></text>
</staticText>
</frame>
</band>
</detail>
</jasperReport>
Output
Additional design notes
As you can see in output there is a 4px height difference between the green and black box, this is due to the empty space you have between the frames. If you need pixel perfect reports you need to have zero space between the components that you are removing/floating.
Maybe you can try using multiple Detail bands for your report. Thus you can use the property printWhenExpresion on each band, instead of in each frame.
Here you can find your jrxml code modified with an example.

Unable to view text in columnHeaders in jasper report

I am trying to create a jasper report (pdf format) that displays list of calls handled. The report is getting created but the heading are not being shown. I have tried to make changes in style but nothing seems to work for this case.
I am using the following libs for this
- jasper-compiler-jdt-5.5.15.jar
- jasperreports-6.2.0.jar
- jasperreports-fonts-6.0.0.jar
- itext-2.1.7.jar
- itextpdf-5.5.10.jar
Following is part of jrxml file
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StockReport" pageWidth="1200" pageHeight="600" columnWidth="50" leftMargin="35" rightMargin="35" topMargin="50" bottomMargin="40">
<parameter name="Title" class="java.lang.String"/>
<field name="id" class="java.lang.Long"/>
<field name="dateTime" class="java.util.Date"/>
--------------------------------------------------
<title>
<band height="50" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="0" y="5" width="960" height="30"/>
<textElement textAlignment="Center">
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{Title}]]>
</textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="20" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="55" y="5" width="1000" height="15" forecolor="#FFFFFF" backcolor="#8c8c8c"/>
<textElement textAlignment="Center">
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Daily Reports"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="55" y="4" width="30" height="15" forecolor="#FFFFFF" backcolor="#b30000"/>
<textElement textAlignment="Left">
<font isBold = "true"/>
</textElement>
<text>
<![CDATA["Record Id"]]>
</text>
</staticText>
<staticText>
<reportElement positionType="Float" mode="Opaque" x="85" y="4" width="100" height="15" forecolor="#FFFFFF" backcolor="#b30000"/>
<textElement>
<font isBold = "true"/>
</textElement>
<text>
<![CDATA["Date/Time"]]>
</text>
</staticText>
-------------------------------------------
</band>
</columnHeader>
<detail>
<band height="80" splitType="Stretch">
<textField>
<reportElement x="65" y="4" width="15" height="60"/>
<textElement textAlignment="Left"/>
<textFieldExpression class="java.lang.Long"><![CDATA[$F{id}]]>
</textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="95" y="4" width="90" height="60"/>
<textElement/>
<textFieldExpression class="java.util.Date"><![CDATA[$F{dateTime}]]></textFieldExpression>
</textField>
-----------------------------------------------------
This is my jrxml file.
It is displaying all the data correctly except the column headers. I cannot understand what the problem is. Also I am getting the following warning
WARN [net.sf.jasperreports.engine.export.PdfGlyphRenderer] -------- Unpatched iText found, cannot use glyph rendering
Screenshot of generated pdf (some details have been scratched off)
Any help will be highly appreciated.
I am not using iReport tool. Currently the use of the same is restricted to our group. Please suggest a solution other than this.
Thanks in advance.
Thanks to all who helped.
The problem was not related to itext and was related to element styling.
The updated code is as follows.
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StockReport" pageWidth="1200" pageHeight="600" columnWidth="50" leftMargin="35" rightMargin="35" topMargin="50" bottomMargin="40">
<parameter name="Title" class="java.lang.String"/>
<field name="id" class="java.lang.Long"/>
<field name="dateTime" class="java.util.Date"/>
--------------------
<title>
<band height="50" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="0" y="5" width="960" height="30"/>
<textElement textAlignment="Center">
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{Title}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="20" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="55" y="5" width="1000" height="15" forecolor="#FFFFFF" backcolor="#8c8c8c"/>
<textElement textAlignment="Center">
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Daily Reports"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height = "23">
<staticText>
<reportElement mode = "Opaque" x = "55" y = "3"
width = "1000" height = "15" backcolor = "#70A9A9" />
<box>
<bottomPen lineWidth = "1.0" lineColor = "#CCCCCC" />
</box>
<textElement />
<text><![CDATA[]]> </text>
</staticText>
-------------------------------------
<staticText>
<reportElement x = "85" y = "3" width = "100" height = "15" />
<textElement textAlignment = "Center" verticalAlignment = "Middle">
<font isBold = "true" />
</textElement>
<text><![CDATA[Date/Time]]></text>
</staticText>
<staticText>
<reportElement x = "55" y = "3" width = "30" height = "15" />
<textElement textAlignment = "Center" verticalAlignment = "Middle">
<font isBold = "true" />
</textElement>
<text><![CDATA[#Id]]></text>
</staticText>
</band>
What i did is that I simply added a element, with no text content to be used as column header banner and added the header text on top of it by specifying the position.
I am not sure of the logic behind this. As for the warning, the Unpatched iText found, cannot use glyph rendering still persits. I am not sure of how to resolve that, but the above cited helped me resolve the initial problem. I hope this would help if anyone come across a similar issue.
Once again thanks to all those who helped and as suggested in above comments I will try to do the same with updated libraries and will definitely edit my post with updated results if it help solve the issue.

JasperReports: Not support & sign when i use style

Working in JasperReports:
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction and instruction</style>
Not Working in JasperReports:
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction & instruction</style>
Why this is happening?
I have used
&amp;
instead of "&" and it is working in jasper report.
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp; instruction</style>
//In text filed i have used style tag.
<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="290"
height="15"
key="textField"
isRemoveLineWhenBlank="true"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" rightPadding="5" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" isStyledText="true">
<font size="9"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp; instruction</style>]]></textFieldExpression>
</textField>
Try to use & instead of using & symbol.
The working sample:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail">
<style name="style1" forecolor="#FF0000" fontName="Serif" isBold="true" isItalic="true"/>
<title>
<band height="182" splitType="Stretch">
<staticText>
<reportElement style="style1" x="27" y="15" width="515" height="20"/>
<textElement/>
<text><![CDATA[Instruction and instruction]]></text>
</staticText>
<staticText>
<reportElement style="style1" x="27" y="46" width="515" height="20"/>
<textElement/>
<text><![CDATA[Instruction & instruction]]></text>
</staticText>
<staticText>
<reportElement x="27" y="78" width="515" height="20"/>
<textElement markup="styled"/>
<text><![CDATA[<style isBold='true'>Instruction and instruction</style>]]></text>
</staticText>
<staticText>
<reportElement x="27" y="108" width="515" height="20"/>
<textElement markup="styled"/>
<text><![CDATA[<style isBold='true'>Instruction & instruction</style>]]></text>
</staticText>
</band>
</title>
</jasperReport>
Note: The styled markup is using in this sample.
The result will be:
For more details you can view Creating Styled Text Using a Markup Language post and my answer on Style a text field in JasperReports question.