different pages on change of group in jasper reports - jasper-reports

My report groups contains 4-5 table component which will be printed each time when group changed.I don't want to print multiple entries of same group in the table components inside the group.

<textField>
<reportElement x="150" y="0" width="60" height="20" isPrintRepeatedValues="false" />//**isPrintRepeatedValues="false"**
<textElement textAlignment="Left">
<font isBold="false" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{activityname}]]></textFieldExpression>
</textField>
<textField>

Related

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 reports grouping not working as expected

I am running a jasper report on an select query, I am grouping the result by few values and using the same fields in my header
Below is my jasper group expression and header.
<groupExpression><![CDATA[$F{tray_code} + $F{card_id} + $F{card_position}+$F{card_number}+ $F{card_from_date}+ $F{card_to_date} + $F{week_number}+$F{patient_id} + $F{patient_full_name}]]></groupExpression>
<groupHeader>
<band height="15">
<textField isBlankWhenNull="true">
<reportElement x="5" y="0" width="20" height="14" uuid="97fd5e2c-50e4-46e4-9c1b-0453f5cd05b5"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{tray_code}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="26" y="0" width="44" height="14" uuid="d16ea2fb-367a-4b5e-986e-bc19669c3091"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{card_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="95" y="0" width="25" height="14" uuid="b7eb1f75-44d4-467e-8463-29f6f6f4555b"/>
<textElement textAlignment="Center">
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{card_position}]]></textFieldExpression>
</textField>
<textField pattern="">
<reportElement x="120" y="0" width="55" height="14" uuid="10e4bc1b-cfbb-478d-bd10-a6284bd3bac1"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse($F{card_from_date}))]]></textFieldExpression>
</textField>
<textField pattern="dd/MM/yyyy">
<reportElement x="175" y="0" width="55" height="14" uuid="a7d34de5-c4de-4093-9da7-96119450c3ab"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse($F{card_to_date}))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="230" y="0" width="24" height="14" uuid="9cf3bce2-cb70-45e7-8199-0d6c8003ce53"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{week_number}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="270" y="0" width="67" height="14" uuid="d9e50bb7-1616-4d84-b92f-246abd05ae7b"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{patient_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="337" y="0" width="250" height="14" uuid="b06f0d0d-739b-4e2a-a2bc-1686c9d5cbfe"/>
<textElement>
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{patient_full_name}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="14" width="752" height="1" uuid="968c2e25-462d-4b0a-90e2-34570db25d0f"/>
<graphicElement>
<pen lineWidth="1.0" lineStyle="Dashed" lineColor="#999999"/>
</graphicElement>
</line>
<textField>
<reportElement x="70" y="0" width="25" height="14" uuid="7f4ba299-706f-4ba6-aafc-ffa47b0e4374"/>
<textElement textAlignment="Center">
<font fontName="DejaVu Sans" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{card_number}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
According to the above group expression, I expect only one header for a group, But I see the group header for the same group is repeated in my output file ! Please let me know what I am doing wrong.
Thanks in Advance.
So there is an issue that happens when you use multiple group headers. The first header behaves like expected ordered by Column Value A only on unique values.
The 2nd header using Column Value B will print on every row despite being non-unique values.
In theory you should be able to use:
1.
ORDER BY ValueA, ValueB
to properly display the report assuming you are using sql, plsql, etc...
However, in my case that did not happen, though for others it seems to work.
2.
Use subreports to attach the minor differences via unique reports.
You create a root report with empty details.
Then you create Unique reports to serve as sub reprots.
Finally, you use the subreport element to link the values into the root report. Though that is a good bit of work and may cause repeat code.
A hacky way I used was:
A mixture of "Print When Expressions" with logical boolean like below
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("QueryA") && $P{P_parameter} == null)
and
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("P_QueryA") && $P{P_parameter} != null)
with two group headers and a column header. The column header will not repeat for every row so you assign one of the booleans expressions to it's "print when" so it does not always print. The first group header will not repeat for every row and works. The 2nd group header is used for the times you DO want it to repeat for every unique value since it always prints for every row, and you use the other boolean on it's "print when".
Hope it helps

Serial Number Repeating in Jasper Reports

I have used $V{REPORT_COUNT} TO DISPLAY SERIAL NUMBER OF THE RECORDS.For Each Record that is fetched from the database the serial number is displayed correctly.
However if one record that is printed has data more then it can accommodate on a page, it is displayed on the next page. I am fine with that too, however the serial number is again shown for that page Eg. 3 is the serial number and if 3 could not be accommodated on the same page the record is written in the next page and the order of serial number is 1 2 3 (First Page) 3 4 5 etc(second Page).
I want 3 to be displayed only once in the first page and not in the second page. I have uploaded a image of my layout and I do not want to show the circled part I am Using Ireport to design the page
Text Field Properties
This is for the REPORT_COUNT TEXTFIELD
<reportElement
mode="Opaque"
x="0"
y="0"
width="15"
height="30"
backcolor="#D3D3D3"
key="textField-9"
stretchType="RelativeToBandHeight"
positionType="Float"
isPrintRepeatedValues="false"
isRemoveLineWhenBlank="true"
isPrintWhenDetailOverflows="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Times New Roman" pdfFontName="Times-Bold" size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
This properties for the right hand side text box which displays data:
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Opaque"
x="12"
y="0"
width="523"
height="13"
forecolor="#000000"
backcolor="#D3D3D3"
key="textField-2"
positionType="Float"
isRemoveLineWhenBlank="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement verticalAlignment="Middle">
<font fontName="SansSerif" pdfFontName="Times-Bold" size="8" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[" "+$F{vesselName}+($F{type} == null ? "" : " ("+$F{type}+")")]]></textFieldExpression>
</textField>
Can you just tell us the properties you have set for the text fields?
I have just made a rough design of your scenario and I did not come across your issue. The row_count value is not getting repeated.
Refer below image.
Set a few properties to your variable:
<variable name="RECORD_COUNT" class="java.lang.String" incrementType="Column" calculation="Count">
<initialValueExpression><![CDATA[1]]></initialValueExpression>
</variable>

The report with several columns: How to reprint group headers in each column?

I'm creating a report with 2 columns per page with JasperReports 4.7.1.
When the records belonging to a group span across multiple columns, I want to print the header not only at the beginning of the group but also at the start of each column.
Using Reprint Header (isReprintHeaderOnEachPage property) in group properties, header can be printed at the start of each page. But I still couldn't find a way to do the same at the start of a new column.
How can I achieve this?
Screenshot of the current report page...
What I want to achieve (note the headers in the 2nd column)...
I had a similar issue to yours and I managed to solve it by adding a ColumnHeader band and only displaying it for the 2nd column of my 2-column report.
It is important to have isReprintHeaderOnEachPage set to true and the height of the groupHeader and columnHeader to be the same for my solution to work.
Here is the relevant code (of course you replace "telephoneNumber" with your appropriate group expression:
<group name="telephoneNumberGroup" isStartNewPage="true" isReprintHeaderOnEachPage="true">
<groupExpression><![CDATA[$F{telephoneNumber}]]></groupExpression>
<groupHeader>
<band height="17">
<textField>
<reportElement positionType="Float" x="5" y="0" width="170" height="15" uuid="5e8b892b-f907-4907-9c6d-4419e57325e5"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="6" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{telephoneNumber}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<columnHeader>
<band height="17">
<printWhenExpression><![CDATA[$V{COLUMN_NUMBER} == 2]]></printWhenExpression>
<textField>
<reportElement positionType="Float" x="5" y="0" width="170" height="15" uuid="5e8b892b-f907-4907-9c6d-4419e57325e5"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="6" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{telephoneNumber}]]></textFieldExpression>
</textField>
</band>
</columnHeader>

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>