I wonder if it's possible to position dynamically growing (table) element to the bottom of the page? My table element is on detail band, just above the page footer band.
Basically in my case the position of the topmost row of the table would be dynamically changing all the time based on the amount of rows in the table. But I'm not sure if creating this kind of presentation is even possible with Jasper where the table would be basically "growing" from bottom to top where the last row of the table would be basically fixed to the bottom of the page, just above page footer. There would be no problem if the position of the table's topmost row would be always fixed and table would "grow normally" from the fixed top position towards the bottom of the page...
I tried setting the table's position type property to Fix relative to bottom, but after that the whole table disappeared completely. This was the only thing I was able to think of so far to solve my issue.
Maybe the easiest way to achieve this is to put your table in a <groupFooter> with footerPosition="StackAtBottom"
The correct way to group depends on your datasource, but let assume you have just one table creating a dummy group.
Example of dummy group with table StackAtBottom of page
<?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="Example2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ca579c38-1e4f-4993-a020-efcea9d1096e">
<style name="table"><box><pen lineWidth="1.0" lineColor="#000000"/></box></style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style>
<subDataset name="Table" uuid="982be61b-ae46-4404-a9a0-30ba13e8c414">
<queryString language="xPath">
<![CDATA[/report/table/entry]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="class" class="java.lang.String">
<fieldDescription><![CDATA[class]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/report]]>
</queryString>
<group name="dummy" footerPosition="StackAtBottom">
<groupFooter>
<band height="29">
<componentElement>
<reportElement key="table" style="table" x="0" y="0" width="360" height="20" uuid="53ea5a0e-1218-4150-ab5a-5f947e73b284"/>
<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">
<datasetRun subDataset="Table" uuid="64092841-9993-4ccd-89b4-84a546c719cf">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("report/table/entry")]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="4f5b1813-a9cc-4f83-9bdb-b0d8c4299133">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="f1a97e19-e23d-40b6-ad95-10614f516db7"/>
<textFieldExpression><![CDATA[$F{class}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="98cfbe63-f865-419c-ad8f-d8af2ed706ba">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="0480f047-02ba-4ec4-b12a-ef56a3cbfee9"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</groupFooter>
</group>
<detail>
<band height="17" splitType="Stretch"/>
</detail>
</jasperReport>
Result
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
In jasper Soft Studio ,I have 2 page footers. For footer one, I want the position should be normal and for footer 2, I want position force to bottom. How can I do that?
If I am setting the position to force to bottom by default the position for both changes to force to bottom but I want one at bottom and second at normal.
I don't think you are using page footers. I'm assuming you have two footer bands for one group. As both of these footer bands belong to the same group they share the same properties. I'd say maybe use one group footer band (set to normal) and the page footer (which is at the bottom by default) or a second group with a same expression which will give you two independent group footers.
Here is an example that groups on $F{Country} with two (independent) groups.
<?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="Blank_A4_" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62ac07f5-f11e-4179-aedb-a42e850c1ea8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="northwind"/>
<queryString language="jsonql">
<![CDATA[Northwind.Customers]]>
</queryString>
<field name="City" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="City"/>
<fieldDescription><![CDATA[City]]></fieldDescription>
</field>
<field name="Country" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="Country"/>
<fieldDescription><![CDATA[Country]]></fieldDescription>
</field>
<field name="ContactName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="ContactName"/>
<fieldDescription><![CDATA[ContactName]]></fieldDescription>
</field>
<sortField name="Country"/>
<group name="City" footerPosition="ForceAtBottom">
<groupExpression><![CDATA[$F{Country}]]></groupExpression>
</group>
<group name="Group1">
<groupExpression><![CDATA[$F{City}]]></groupExpression>
</group>
<group name="Country 1" footerPosition="ForceAtBottom">
<groupExpression><![CDATA[$F{Country}]]></groupExpression>
<groupHeader>
<band height="52">
<textField>
<reportElement x="180" y="0" width="200" height="52" uuid="ecbaf5bf-be63-4f90-930c-dabb2c385d33"/>
<textElement textAlignment="Center">
<font size="35"/>
</textElement>
<textFieldExpression><![CDATA[$F{Country}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
<groupFooter>
<band height="20">
<textField>
<reportElement x="180" y="0" width="200" height="20" uuid="fc3ccc02-ea1b-4aa3-84d0-e40ba46f3966"/>
<textElement textAlignment="Center">
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{Country}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<group name="Country 2">
<groupExpression><![CDATA[$F{Country}]]></groupExpression>
<groupFooter>
<band height="20">
<textField>
<reportElement x="180" y="0" width="200" height="20" uuid="fb7c7dad-07c1-428d-873e-cb1eae0c00d7"/>
<textElement textAlignment="Center">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{Country}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<detail>
<band height="30">
<textField>
<reportElement x="180" y="0" width="365" height="30" uuid="8edf2d40-c8e5-40d0-9bcd-3051581e7acb"/>
<textFieldExpression><![CDATA[$F{City}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="170" height="30" uuid="4fa050bf-8bbb-47ce-8108-6e9ba25ac668"/>
<textFieldExpression><![CDATA[$F{ContactName}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I'm new in Jasper reports, so I'll write my whole task, if it's allowed..
I'm trying to parse json data to print in it PDF. Data is coming from oracle DB, written in CLOB column, so I have list of json-clob records.
I have nested lists json (and clob) data, so I can't build 3 stair nested report with my jasper experience. I have json structure like this:
{
title: 'Main Title',
blocks: [{
title: 'Inner Title',
items: [{
key: '1',
value: 'some text'
}, {
key: '2',
value: 'some other text'
}]
}, {
text: 'here may be other fields (text, not title)'
}]
}
For this json data, I want to get this result in PDF (just simple output):
Main Title
Inner Title
1 some text
2 some other text
here may be other fields (text, not title)
Firstly, I use CLOB converting in json source ( script:
< dataSourceExpression >
< ![CDATA[new net.sf.jasperreports.engine.data.JsonQLDataSource(new ByteArrayInputStream($F{JSON_CLOB_RECORD}.getBytes("UTF-8")))]] >
< /dataSourceExpression >
source: nested jasper subreports with json datasource ).
After that, I use jr:list and textfield to print main titles. And I'm done, don't know how to continue.
I searched nested lists (jr:list) but nothing, can't fit to my task.
P.S. I have subDataset for parsing data from CLOB to json with fields title (java.lang.String) and blocks (I tried here java.util.Collection and ArrayList but errors occurred, than I wrote java.lang.Object. Is it necessary to write blocks field in this subDataset?). I also added subDataset for blocks list, is it needed? And if yes, so I have to add items subDataset too, right? Also, I tried to add subReport after main title textfield, for blocks list and added dataSourceExpression but can't continue.
Need some help.
I would suggest using a subreport, instead of a list or nested lists, because you gain more flexibility in this case.
In the main report you should discard the list element and the dataset and use a subreport, something like:
<subreport>
<reportElement x="0" y="0" width="550" height="50" uuid="37861aca-d444-4aec-ad03-baa310540327"/>
<subreportParameter name="JSON_INPUT_STREAM">
<subreportParameterExpression><![CDATA[new ByteArrayInputStream($F{JSON_CLOB_RECORD}.getBytes("UTF-8"))]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["Subreport.jasper"]]></subreportExpression>
</subreport>
Here we only need the JSON_INPUT_STREAM so that the subreport will construct a dataSource based on the query and its language.
Case 1. If you are mostly interested in the items key, then the subreport(Subreport.jrxml) could be pretty basic like so:
<?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="Subreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3dd10f8-b28c-4c11-b582-9b169e8aa417">
<queryString language="jsonql">
<![CDATA[..items.*]]>
</queryString>
<field name="mainTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="$.title"/>
</field>
<field name="key" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="key"/>
</field>
<field name="value" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="value"/>
</field>
<field name="blockTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^.title"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="90" splitType="Stretch">
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="172de051-3d2c-4458-b01e-ab06e4e1bb3b"/>
<textFieldExpression><![CDATA[$F{blockTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="94f57756-a5a8-402f-ad23-7cdbe2a00e59"/>
<textFieldExpression><![CDATA[$F{mainTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="100" height="30" uuid="7dbbdfd8-5a0e-4288-ae39-21f13cd4d921"/>
<textFieldExpression><![CDATA[$F{key} + " " + $F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Notice the isPrintRepeatedValues="false" and the isRemoveLineWhenBlank="true" properties that remove the duplicates and the lines so that you get the desired output.
I've simulated your case with a serialized JSON and got the following:
Case 2. If you are interested in all the blocks object data you would have to land on the blocks item in your query and create a list/subreport for the items key, something like:
<?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="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3dd10f8-b28c-4c11-b582-9b169e8aa417">
<subDataset name="BlockItemsDataset" uuid="83c1b8ed-e880-4474-a809-39d95277341f">
<field name="key" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="key"/>
</field>
<field name="value" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="value"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[blocks]]>
</queryString>
<field name="mainTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="$.title"/>
</field>
<field name="blockTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="title"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="91" splitType="Stretch">
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="94f57756-a5a8-402f-ad23-7cdbe2a00e59"/>
<textFieldExpression><![CDATA[$F{mainTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="172de051-3d2c-4458-b01e-ab06e4e1bb3b"/>
<textFieldExpression><![CDATA[$F{blockTitle}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="61" width="200" height="30" uuid="7a94d84d-d58e-4508-b143-3704fa7f5cd3"/>
<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="BlockItemsDataset" uuid="a866f955-7594-4fb9-9bb2-936282963dea">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("items")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="200">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="36a771fa-f949-4c69-a62c-1df0c610a2d3"/>
<textFieldExpression><![CDATA[$F{key} + " " + $F{value}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
I have a text for a document, that can repeat itself for more than 100 times, what I was trying to do is putting a lot of textfield's and then putting a print when expression so that only the quantity of the parameters that I gave would repeat.
The problem is that it can repeat more times than I thought. I like to pass as parameter the number of times it should repeat, not using datasource.
An easy way to repeat text would be to actually use a datasource, the JREmptyDataSource in constructor you can define how many records you like.
I will show an example using the jr:list component to repeat text, but you could use the jr:table component or a subreport instead.
Pass to this component an empty datasource with the number of records you like (hence the parameter defined):
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{NR_REPEAT})]]></dataSourceExpression>
Full 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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="716e18ba-d975-40fa-9be2-89f43a4ab69c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="RepeatDataset" uuid="185d5db2-6f6b-4c9a-9905-e7a554b6a8fa">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<parameter name="NR_REPEAT" class="java.lang.Integer">
<defaultValueExpression><![CDATA[5]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="22">
<textField>
<reportElement x="0" y="0" width="260" height="20" uuid="b0a2bf35-f015-4b85-aa87-b5587e48de10"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["NR. REPEAT IS: " + $P{NR_REPEAT}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="31" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="550" height="22" uuid="0d5f8ed2-c697-4337-b0b0-2411da8cc5fa">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</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="RepeatDataset" uuid="e98a25f7-2d4e-403e-8199-0d3573bb3a3e">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{NR_REPEAT})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="22" width="550">
<textField>
<reportElement x="0" y="0" width="550" height="22" uuid="21984a90-5517-4c8b-82f0-1fe682728830">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT} + " - Hello world"]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
Output setting NR_REPEAT to 5
I have an input parameter which is an ID.
I want to use a lookup table in the database to expand that ID into a long name for use in the report title.
How could I just add text into a textfield from a SQL query without needing to worry about rows of tabular data?
You can use the List component in the Title band. This List (or Table component) will be associated with another additional (non main) datasource for showing information (the Name by Id passed via Parameter in your case).
The main datasource will be used by Detail band (or another Table component with the its own datasource) for showing data filtered by parameter's value (Id in your case).
With help of textField's property isStretchWithOverflow (with true value) we can garantee that all text will be drawing with the textField.
The sample
In this sample I've used the DB distributed with the Jaspersoft Studio. The parameter addrId was used for filtering data by the id field of address table. This parameter was mapped to the List's datasource parameter with the same name (addrId). Yes, I've used the List component placed on Title band for showing information about the value of our external parameter (the city and the street of address in this sample). At the Detail band we are showing the information about documents (table document) related to our address (defined by addrId)
The report's template
<?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="growing_text" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="77f0cb04-7f4b-43dc-af12-89c25fa7c58c">
<subDataset name="dsAddrTitle" uuid="0eb7cd0c-f4f1-408d-be13-dc484fda80d5">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<parameter name="addrId" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT city + ', ' + street AS name FROM address WHERE id=$P{addrId}]]>
</queryString>
<field name="NAME" class="java.lang.String"/>
</subDataset>
<parameter name="addrId" class="java.lang.Integer">
<defaultValueExpression><![CDATA[33]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT ID, ADDRESSID, TOTAL FROM DOCUMENT WHERE ADDRESSID=$P{addrId} ORDER BY ADDRESSID]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="ADDRESSID" class="java.lang.Integer"/>
<field name="TOTAL" class="java.math.BigDecimal"/>
<title>
<band height="10" splitType="Stretch">
<componentElement>
<reportElement x="160" y="0" width="40" height="10" uuid="f4cb4e5c-e2d7-4927-b143-4cfcd7d99b76"/>
<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" ignoreWidth="true">
<datasetRun subDataset="dsAddrTitle" uuid="4bf3eb57-f752-4856-ac3a-fd7e3a33f434">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<datasetParameter name="addrId">
<datasetParameterExpression><![CDATA[$P{addrId}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="30" width="100">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="40" height="10" uuid="1b533c30-7868-450b-a5b9-59d5130dcb67"/>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</title>
<columnHeader>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="185" height="30" uuid="100faa3b-790d-4dc6-b86c-8911a8762207"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="185" y="0" width="185" height="30" uuid="aef6af65-f7b5-42e9-a102-aeb272f99103"/>
<text><![CDATA[ADDRESSID]]></text>
</staticText>
<staticText>
<reportElement x="370" y="0" width="185" height="30" uuid="2c176a21-6387-4505-836e-7e250751755f"/>
<text><![CDATA[TOTAL]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="185" height="30" uuid="22cbe96d-5322-40e3-bd96-d2aa9bf35dd2"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="185" y="0" width="185" height="30" uuid="3adedcc9-f60e-4664-bbe8-6b7d7b8e13a4"/>
<textFieldExpression><![CDATA[$F{ADDRESSID}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00#">
<reportElement x="370" y="0" width="185" height="30" uuid="48041fd6-1375-4819-8ebb-ffd4aef84889"/>
<textFieldExpression><![CDATA[$F{TOTAL}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The output result
I need to create table of contents in JasperReports.
I have already achieved this, but cant do anything with lines in TOC.
Currently they have a static width:
Chapter 1 ........ 2
Long Chapter Name ........ 3
End ........ 4
I want to stretch dotted lines to the width of the chapter name. Like here:
Chapter 1 ................. 2
Long Chapter Name ......... 3
End ....................... 4
How can I do this? Is there some 'padding' functionality in JR or should I create scriptlet for this task ? Thanks!
P.S. I'm using jasper reports 5.0.1
This wouldn't be a very neat way but I would draw many dots in your text box and hide the end using a frame to allow writing the number of the page.
<?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="table of content" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="df5894b6-0e62-4082-bdb8-3f0a1b26a2f4">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT
1 AS page,
'test' AS title
FROM
"account" account
Union
SELECT
4 AS page,
'chapter 2' AS title
FROM
"account" account
Union
SELECT
20 AS page,
'chapter 3: hello' AS title
FROM
"account" account]]>
</queryString>
<field name="page" class="java.lang.Integer"/>
<field name="title" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="2e81fd32-3b8d-4b98-b96d-6409afb8d16f" x="0" y="0" width="555" height="20"/>
<textElement>
<font isBold="true" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[Table of content]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="c8707508-946a-48ae-ae75-61810003e1db" x="0" y="0" width="555" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{title}+" .............................................................................................................................."]]></textFieldExpression>
</textField>
<frame>
<reportElement uuid="4040d203-6b49-4da2-8bcf-f3d6d48c7fd7" mode="Opaque" x="341" y="0" width="214" height="20"/>
</frame>
<textField>
<reportElement uuid="472f8f95-fdea-4cd9-b3a5-a1b9b66a8c44" mode="Opaque" x="321" y="0" width="20" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{page}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>