How to combine two textFields into one box in RTF generated by Jasper reports? - 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.

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>

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>

different pages on change of group in 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>

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>

stretch a row to fit the data in jasper reports using iReport

How do i stretch a text field to fit the data, If data exceeds the band height the text field doesn't stretch. I have added the text field tag in my jrxml...
The example:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
style="dNew"
mode="Opaque"
x="200"
y="0"
width="200"
height="19"
key="value-2"
stretchType="RelativeToTallestObject"
positionType="Float"
isPrintInFirstWholeBand="true"
isPrintWhenDetailOverflows="true"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>
Some bands do not stretch, but if you are talking about the detail band you can do something like this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="base" positionType="Float"
isPrintRepeatedValues="false" x="0" y="3"
width="380" height="26" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{information}]]></textFieldExpression>
</textField>
That is pasted from auto generated XML so there is a lot of extra stuff, but the isStretchWithOverflow="true" should work for you. This will make the field stretch down as the text fills it up.
I ususally use iReport to build my reports and it works quiet nicely. You can switch to an XML view in there too.