java


Empty table generation from DynamicJasper


I am trying to generate a table with custom jasper template and with input parameter. However I always endup with an empty pdf.
My jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2016-11-15T11:03:31 -->
<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="TestTable" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3a04a168-100e-462e-9951-68ce7dd6320a">
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset2" uuid="c04cf905-61fa-4de6-bd54-079e65365b31">
<queryString>
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="price" class="java.lang.String"/>
</subDataset>
<parameter name="TestParam" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="277" splitType="Stretch">
<componentElement>
<reportElement x="0" y="77" width="555" height="200" uuid="1b811fb1-5660-4d3f-99f7-0070b044363c">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</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">
<datasetRun subDataset="Dataset2" uuid="22d4fa75-1f8f-4911-a365-c74966c1f2fa">
<dataSourceExpression><![CDATA[$P{TestParam}]]></dataSourceExpression>
</datasetRun>
<jr:column width="150" uuid="50b18030-4c95-4992-977c-4ed2e8d3c430">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="150" height="30" uuid="c909101c-8f62-4800-bb1e-f2bee23df6e9"/>
<text><![CDATA[Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="150" height="30" uuid="3cb2bbbf-5a84-499a-b105-bb85de3012a4"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="130" uuid="be433f76-a9d7-4c78-9431-8dca6a3cede0">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="130" height="30" uuid="16175e90-0f18-4628-a9f7-952baa9823ae"/>
<text><![CDATA[Price]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="130" height="30" uuid="82a2f8fb-9702-4ce7-93a5-2032dd83b884"/>
<textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</title>
<detail>
<band height="95" splitType="Stretch"/>
</detail>
</jasperReport>
My Main class
public class ItemPriceReporter {
public static void main(String[] args) throws FileNotFoundException, JRException {
new ItemPriceReporter().generateReport();
}
private void generateReport() throws JRException, FileNotFoundException {
DynamicReportBuilder drb = new DynamicReportBuilder();
drb.setTemplateFile("TestTable.jrxml");
Map<String, Object> params = new HashMap<>();
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(generateItems());
params.put("TestParam", dataSource);
JasperReport jasperReport = DynamicJasperHelper.generateJasperReport(drb.build(), new ClassicLayoutManager(), params);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
FileOutputStream fos = new FileOutputStream("TestTable.pdf");
pdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(fos));
pdfExporter.exportReport();
}
private List<Item> generateItems() {
List<Item> items = new ArrayList<>();
Item item = new Item("test", "10");
items.add(item);
item = new Item("test2", "20");
items.add(item);
return items;
}
}
My Item Bean
public class Item {
private String name;
private String price;
public Item() {
}
public Item(String name, String price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
Can someone point out what am I missing here?
EDIT: Updated the jrxml with table moved to Title band

Related Links

How to navigate between html & jsp pages in spring
How to host java application in aws?
How to serialize this program and deserialize it
Initialization statement
return id in ON DUPLICATE KEY in JOOQ
how to draw lines with opencv in java
The Composite doesn't scroll when its inner components enlarge in swt
Java and CMD Runtime Executor
What's the convention for reusing variable names for both JSP pages and Java Servlets?
How can I run integration tests on a jersey application without restarting the server for every test?
#Autowire failure for JPA Repository in multi-module project
How can we tell Hibernate to make identifier properties as optional
Importing External library in java gives runtime no class found error
How to make a single JComponent render aliased text in Swing?
Make the entire row bold using Apache POI
Streaming Data Generator

Categories

HOME
cakephp
wso2
pypi
urbancode
image-processing
fluentd
nullpointerexception
analysis
amortized-analysis
malloc
v8
baqend
azure-storage-tables
add
amazon-cloudformation
awesome-wm
dacpac
php-7.1
hex-editors
ups
clearcase-ucm
reactcsstransitiongroup
conemu
zapier
scriptcs
accessor
format-specifiers
android-widget
buildbot
poltergeist
url-scheme
uninstall
fifo
elasticsearch-net
librato
socialengine
twilio-api
siesta-swift
calibre
vsts-build-task
libraries
android-browser
angularjs-factory
bootstrapper
trim
broadcastreceiver
janrain
cubic-spline
taffy
youcompleteme
theming
clean-architecture
domain-model
directory-structure
feeds
typed-lambda-calculus
np-complete
pearson
spring-cache
bind9
smart-table
heidisql
intrusion-detection
player
gridview-sorting
websitepanel
lttng
moveit
actionbardrawertoggle
python-stackless
pagerank
ipconfig
goose
freedesktop.org
rtbkit
thredds
marching-cubes
retina
map-projections
system32
oxwall
xcode-6.2
document-classification
responsive-slides
openexr
undefined-reference
didselectrowatindexpath
html5-notifications
commoncrypto
excel-2003
eclipse-memory-analyzer
pygit2
sabredav
wsdl-2.0
free-variable
dmoz
quickdialog
dsn
dbproviderfactories
window-management
self-extracting
krl
google-friend-connect
routedevent
dbal
premature-optimization

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App