Jump to content
JasperReports Library 7.0 is now available ×

datasource in a crossta using JavaBean??


Recommended Posts

By: gouwa - gouwa

datasource in a crossta using JavaBean??

2006-01-05 01:17

Can I use JavaBean as datasource in a crosstab?

I can set a subDataset in a crosstab with following and it works ok:

<subDataset name="data">

<queryString><![CDATA[sELECT * FROM month2 group by txCatalog,devCatalogNo]]></queryString>

<field name="txCatalog" class="java.lang.String"/>

<field name="devCatalogNo" class="java.lang.String"/>

<field name="monthDebitCount" class="java.lang.Integer"/>

<field name="monthDebitAmt" class="java.lang.String"/>

<field name="monthSuccess" class="java.lang.Integer"/>

</subDataset>

 

I want to use JavaBean to set a subDataset,it will has no queryString and only has Fields.

Thanks for your reply!

 

 

 

 

 

By: gouwa - gouwa

RE: datasource in a crossta using JavaBean??

2006-01-05 01:23

hi,this is the error:

net.sf.jasperreports.engine.JRException: Cannot instantiate data set.

net.sf.jasperreports.engine.fill.JRFillDatasetRun.evaluate(JRFillDatasetRun.java:125)

net.sf.jasperreports.engine.fill.JRFillElementDataset.evaluateDatasetRun(JRFillElementDataset.java:164)

net.sf.jasperreports.engine.fill.JRFillCrosstab.evaluate(JRFillCrosstab.java:377)

net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:204)

net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummarySamePage(JRVerticalFiller.java:792)

net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:726)

net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:260)

net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:134)

net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:834)

net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:428)

com.zjft.shepherd.analyse.WFixReport.handleRequestInternal(WFixReport.java:1121)

org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:128)

org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)

org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)

org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)

org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)

org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)

javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: datasource in a crossta using JavaBean??

2006-01-05 03:15

How does your crosstabDataset look like?

 

Regards,

Lucian

 

 

 

 

By: gouwa - gouwa

RE: datasource in a crossta using JavaBean??

2006-01-06 00:34

hi,Lucian,here is my raw .jrxml file:

I use sql query as the datasource in the crosstab. Now I want to use JavaBean data to replace the sql query data. How can I do it?

Thanks a lot!

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"

"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

 

<jasperReport name="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="812" leftMargin="15" rightMargin="15" topMargin="10" bottomMargin="10">

 

<import value="iTextAsian.*"/>

<import value="iReport.*"/>

<reportFont name="SongTi" isDefault="false" fontName="æ°“åºè¥ç›²é™†è¯" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>

<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

 

<subDataset name="data">

<queryString><![CDATA[

SELECT * FROM month2 group by txCatalog,devCatalogNo

]]></queryString>

<field name="txCatalog" class="java.lang.String"/>

<field name="devCatalogNo" class="java.lang.String"/>

<field name="monthDebitCount" class="java.lang.Integer"/>

<field name="monthDebitAmt" class="java.lang.String"/>

<field name="monthSuccess" class="java.lang.Integer"/>

</subDataset>

 

<queryString><![CDATA[

SELECT * FROM month2

]]></queryString>

 

 

<summary>

<band height="100">

 

<staticText>

<reportElement x="0" y="20" width="90" height="50"/>

<box topBorder="2Point" leftBorder="2Point" rightBorder="2Point" bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font reportFont="SongTi" isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗绫诲瀷]]></text>

 

</staticText>

<staticText>

<reportElement x="90" y="20" width="120" height="50"/>

<box topBorder="2Point" bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[椤圭洰]]></text>

</staticText>

<crosstab name="Test1" isRepeatColumnHeaders="false">

 

 

<reportElement x="0" y="20" width="812" height="60" mode="Opaque"/>

 

 

<crosstabDataset isDataPreSorted="true">

<dataset>

<datasetRun subDataset="data">

</datasetRun>

</dataset>

</crosstabDataset>

 

 

 

<rowGroup name="txCata" width="90" totalPosition="End">

<bucket>

<bucketExpression class="java.lang.String">$F{txCatalog}</bucketExpression>

</bucket>

 

<crosstabRowHeader>

<cellContents >

<box leftBorder="1Point" bottomBorder="1Point" rightBorder="1Point"/>

<textField>

<reportElement x="5" y="5" width="80" height="30"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<textFieldExpression> $V{txCata}</textFieldExpression>

</textField>

</cellContents>

</crosstabRowHeader>

<crosstabTotalRowHeader>

<cellContents backcolor="#E0FFFF">

<box leftBorder="1Point" bottomBorder="1Point" rightBorder="1Point"/>

<staticText>

<reportElement x="5" y="0" width="85" height="60"/>

<box rightBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[éšå£î…¸]]></text>

 

</staticText>

<staticText>

<reportElement x="90" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗绗旀暟]]></text>

</staticText>

<staticText>

<reportElement x="90" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗閲戦]]></text>

</staticText>

<staticText>

<reportElement x="90" y="42" width="120" height="18"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗鎴愬姛éœå˜³]>%</text>

</staticText>

</cellContents>

</crosstabTotalRowHeader>

 

</rowGroup>

 

<rowGroup name="count" width="120">

<bucket>

<bucketExpression class="java.lang.String"></bucketExpression>

</bucket>

<crosstabRowHeader>

<cellContents>

<box bottomBorder="1Point" rightBorder="1Point"/>

<staticText>

<reportElement x="0" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗绗旀暟]]></text>

</staticText>

<staticText>

<reportElement x="0" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗閲戦]]></text>

</staticText>

<staticText>

<reportElement x="0" y="42" width="120" height="18"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[浜ゆ槗鎴愬姛éœå˜³]>%</text>

</staticText>

</cellContents>

</crosstabRowHeader>

 

</rowGroup>

 

 

<columnGroup name="devCata" height="50" totalPosition="End" headerPosition="Stretch">

<bucket>

<bucketExpression class="java.lang.String">$F{devCatalogNo}</bucketExpression>

</bucket>

<crosstabColumnHeader>

<cellContents >

<box topBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>

<textField>

<reportElement x="5" y="5" width="110" height="40"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">$V{devCata}</textFieldExpression>

</textField>

</cellContents>

</crosstabColumnHeader>

<crosstabTotalColumnHeader>

<cellContents backcolor="#FFFF60">

<box topBorder="2Point" bottomBorder="2Point" rightBorder="2Point"/>

<staticText>

<reportElement x="5" y="5" width="110" height="40"/>

<textElement textAlignment="Center" verticalAlignment="Middle">

<font isBold="true"/>

</textElement>

<text><![CDATA[éšå£î…¸]]></text>

</staticText>

</cellContents>

</crosstabTotalColumnHeader>

 

</columnGroup>

 

<measure name="monthDebitCount" class="java.lang.Integer" calculation="Sum">

<measureExpression>$F{monthDebitCount}</measureExpression>

</measure>

<measure name="monthDebitAmt" class="java.lang.Float" calculation="Sum">

<measureExpression>Float.valueOf($F{monthDebitAmt})</measureExpression>

</measure>

<!-- <measure name="monthSuccess" class="java.lang.Float" calculation="Sum">

<measureExpression>new Float($F{monthSuccess}.floatValue()/$F{monthDebitCount}.floatValue())</measureExpression>

</measure>-->

<measure name="monthSuccess" class="java.lang.Integer" calculation="Sum">

<measureExpression>$F{monthSuccess}</measureExpression>

</measure>

 

<crosstabCell width="120" height="60">

<cellContents backcolor="#FFFFFF">

<box bottomBorder="1Point" rightBorder="1Point"/>

<textField>

<reportElement x="0" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Integer">$V{monthDebitCount}</textFieldExpression>

</textField>

<textField pattern="##################0.00">

<reportElement x="0" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">$V{monthDebitAmt}</textFieldExpression>

</textField>

<textField pattern="#############0.0">

<reportElement x="0" y="40" width="120" height="20"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">new Float($V{monthSuccess}.floatValue()*100/$V{monthDebitCount}.floatValue())</textFieldExpression>

</textField>

</cellContents>

</crosstabCell>

 

<crosstabCell width="120" height="60" rowTotalGroup="txCata">

<cellContents backcolor="yellow">

<box borderColor="black" bottomBorder="1Point" rightBorder="1Point"/>

<textField>

<reportElement x="0" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Integer">$V{monthDebitCount}</textFieldExpression>

</textField>

<textField pattern="##################0.00">

<reportElement x="0" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">$V{monthDebitAmt}</textFieldExpression>

</textField>

<textField pattern="######0.0">

<reportElement x="0" y="40" width="120" height="20"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">new Float($V{monthSuccess}.floatValue()*100/$V{monthDebitCount}.floatValue())</textFieldExpression>

</textField>

</cellContents>

</crosstabCell>

 

<crosstabCell width="120" height="60" columnTotalGroup="devCata">

<cellContents backcolor="yellow">

<box borderColor="black" bottomBorder="1Point" rightBorder="1Point"/>

<textField>

<reportElement x="0" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Integer">$V{monthDebitCount}</textFieldExpression>

</textField>

<textField pattern="##################0.00">

<reportElement x="0" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">$V{monthDebitAmt}</textFieldExpression>

</textField>

<textField pattern="########0.0">

<reportElement x="0" y="40" width="120" height="20"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">new Float($V{monthSuccess}.floatValue()*100/$V{monthDebitCount}.floatValue())</textFieldExpression>

</textField>

</cellContents>

</crosstabCell>

 

 

<crosstabCell width="120" height="60" rowTotalGroup="txCata" columnTotalGroup="devCata">

<cellContents backcolor="yellow">

<box borderColor="black" bottomBorder="1Point" rightBorder="1Point"/>

<textField>

<reportElement x="0" y="0" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Integer">$V{monthDebitCount}</textFieldExpression>

</textField>

<textField pattern="##################0.00">

<reportElement x="0" y="20" width="120" height="20"/>

<box bottomBorder="1Point"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">$V{monthDebitAmt}</textFieldExpression>

</textField>

<textField pattern="######0.0">

<reportElement x="0" y="40" width="120" height="20"/>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression class="java.lang.Float">new Float($V{monthSuccess}.floatValue()*100/$V{monthDebitCount}.floatValue())</textFieldExpression>

</textField>

</cellContents>

</crosstabCell>

 

 

 

</crosstab>

</band>

</summary>

 

</jasperReport>

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: datasource in a crossta using JavaBean??

2006-01-06 02:10

You need to use the datasetRun with a dataSourceExpression. The expression would be something like this: new JRBeanCollectionDataSource(<bean collection>).

 

HTH,

Lucian

 

 

 

 

By: gouwa - gouwa

RE: datasource in a crossta using JavaBean??

2006-01-06 07:00

hi,I get my JavaBean datasource from Hibernate Object. I use it in a normal .jrxml with some field name. Then I compile the .jrxml to .jasper by using JasperCompileManager.compileReport().

Here is my java coding:

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(tempList);

JasperReport jasperReport = (JasperReport)JasperCompileManager.compileReport(pathxml);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);

 

temList is a JavaBean List,pathxml is the location of .jrxml file;

If I use datasetRun in a crosstab, it must contain the subDataset ,so must I define a subDataset?

About the JRBeanCollectionDataSource, I only have some fields from the JavaBean List.

Thanks a lot!

 

 

 

 

By: Lucian Chirita - lucianc

RE: datasource in a crossta using JavaBean??

2006-01-06 08:07

If the crosstab aggregates data from the report data source (ds in your case) you don't need a sub dataset. Check the crosstab samples, one of them doesn't use a dataset.

 

 

 

 

 

By: gouwa - gouwa

RE: datasource in a crossta using JavaBean??

2006-01-06 08:41

Thanks,the problem is done.

 

 

 

 

By: gouwa - gouwa

RE: datasource in a crossta using JavaBean??

2006-01-06 08:05

sorry for bother you. I hava resolved it by accident.

 

 

 

 

By: flyscroll - flyscroll

RE: datasource in a crossta using JavaBean??

2006-01-19 23:03

Could you please tell how did you solve it? can you paste your xml file? thanks

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...