Jump to content
Changes to the Jaspersoft community edition download ×

Jasper Subreports with the same data source


javax_slr

Recommended Posts

Hi! I'm trying create a report with Jasper reports, which contains 2 subreports, working on the same data source (which is custom data source). I.e. those subreports are working on the same data. I have following "main" report jrxml (attached code snippet) and I receive exception: com.cadence.mdv.reporting.ReportingException: net.sf.jasperreports.engine.JRException: The subreport is placed on a non-splitting band, but it does not have a rewindable data source. What should I do in order to get this report working? Thank you


 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"
 "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="BasicReport">
       
<import value="com.cadence.mdv.reporting.ReportUtilities" />
       
<parameter name="Title" class="java.lang.String" />
       
<title>
               
<band height="50">
                       
<textField>
                               
<reportElement x="0" y="0" width="200" height="50" />
                               
<textFieldExpression class="java.lang.String">$P{Title}</textFieldExpression>
                       
</textField>
               
</band>
       
</title>
       
<pageHeader>
               
<band>
               
</band>
       
</pageHeader>
       
<detail>
               
<band height="620" isSplitAllowed="true">
                       
<subreport>
                               
<reportElement x="50" y="0" height="300" width="500" isPrintWhenDetailOverflows="true" />
                               
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                               
<subreportExpression class="java.lang.String"><![CDATA["blockdetails.jasper"]]> </subreportExpression>
                       
</subreport>
                       
<subreport>
                               
<reportElement x="50" y="0" height="300" width="500" isPrintWhenDetailOverflows="true" />
                               
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                               
<subreportExpression class="java.lang.String"><![CDATA["fsmdetails.jasper"]]>   </subreportExpression>
                       
</subreport>
               
</band>
       
</detail>
</jasperReport>[/code]

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

hi javax_slr, i've tried to compile yor main rpt and i met the same exception.

i solved the problem removing by the xml code this import:

javax_slr
Wrote:
 


<...>
      
  <import value="com.cadence.mdv.reporting.ReportUtilities" />
</...>

i don't know why you have to use this package but in all my jrxml files the import of the packages is always the same:

 <import value="java.util.*" />
 <import value="net.sf.jasperreports.engine.*" />
 <import value="net.sf.jasperreports.engine.data.*" />

and i define the package that i need to use in  iReport  (options->classpath)

hope this help you, bye

 

Link to comment
Share on other sites

Hi,

 

If you put a subreport in a band that has splitType="Prevent" (or the former isSplitAllowed="false"), the subreport data source needs to have the ability to start again, in case the band restarts on a new page.

The exception you get tells you that your custom subreport data source needs to implement the JRRewindableDataSource interface from JR.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi,

 

It means you have a design flaw in your report. Or an inconsistency. The infinite loop occurs probably because you have conflicting design options in your reports.

This design flaw cannot be detected by the engine at report compile time nor during report filling.

We would need to see the reports involved in order to figure out what the design flaw is.

 

But just to give you an idea, it is probably related to the fact that you have elements with isPrintWhenDetailOverflow=true.

It might be that the engine tries to reprint elements which in turn cause a page break again and then they need to print again and cause a page break again and again and again.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Thank you,

Now I changed the design using nested reports and different datasources, but still I have infinite loop problem.

 Take a look please

 

 

Code:
------level 0 report -----------------------------<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="BasicReport">    <import value="com.cadence.mdv.reporting.ReportUtilities" />    <parameter name="DSFactory" class="com.cadence.mdv.reporting.JasperDataSourceFactory" />    <parameter name="Title" class="java.lang.String" />       <title>        <band height="50">            <textField>                <reportElement x="0" y="0" width="200" height="50" />                <textFieldExpression class="java.lang.String">$P{Title}</textFieldExpression>            </textField>        </band>    </title>    <pageHeader>        <band>        </band>    </pageHeader>    <detail>        <band height="600" isSplitAllowed="true">            <subreport>                <reportElement x="50" y="0" height="300" width="500" isPrintWhenDetailOverflows="true" />                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>                <subreportExpression class="java.lang.String"><![CDATA["blockdetails.jasper"]]>    </subreportExpression>            </subreport>          </band>    </detail></jasperReport>------level 1 report -----------------------------<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"  "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="BlockDetailReport">	<import value="com.cadence.mdv.reporting.ReportUtilities"/>	<import value="com.cadence.mdv.model.MDVCoverageContainer"/>	<parameter name="Title" class="java.lang.String" />	<parameter name="DSFactory" class="com.cadence.mdv.reporting.JasperDataSourceFactory" />		<queryString><![CDATA[select entity from dto]]></queryString>	<field name="entity" class="com.cadence.mdv.model.MDVBaseEntity" />	<variable name="NAME" class="java.lang.String" calculation="Sum">		<variableExpression>			$F{entity}.getAttributeValue("name")		</variableExpression>	</variable>			<detail>		<band height="500"   isSplitAllowed="true">			<rectangle>				<reportElement mode="Opaque" x="50" y="0" width="420" height="20" backcolor="#CCCCCC"/>			</rectangle>			<rectangle>				<reportElement mode="Transparent" x="50" y="20" width="420" height="250" backcolor="#FFFFFF"/>			</rectangle>			<staticText>				<reportElement mode="Transparent" x="61" y="5" width="200" height="20" backcolor="#FFFFFF"/>				<textElement>					<font fontName="SansSerif" size="10" isBold="true"/>				</textElement>				<text><![CDATA[block coverage for Instance:]]></text>			</staticText>			<textField>				<reportElement mode="Transparent" x="279" y="5" width="130" height="20" backcolor="#FFFFFF"/>				<textElement>					<font fontName="SansSerif" isBold="true"/>				</textElement>				<textFieldExpression class="java.lang.String"><![CDATA[$V{NAME}]]></textFieldExpression>			</textField>			<staticText>				<reportElement x="61" y="39" width="100" height="20"/>				<textElement/>				<text><![CDATA[Covered Blocks:]]></text>			</staticText>			<textField>				<reportElement x="161" y="39" width="130" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createHitOfTotal($F{entity},"selfBlock")]]></textFieldExpression>			</textField>			<staticText>				<reportElement x="61" y="59" width="100" height="20"/>				<textElement/>				<text><![CDATA[ignored Blocks:]]></text>			</staticText>						<textField>				<reportElement x="161" y="59" width="130" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createIgnored($F{entity},"selfBlock")]]></textFieldExpression>			</textField>									<staticText>				<reportElement x="61" y="79" width="100" height="20"/>				<textElement/>				<text><![CDATA[Covered Statements:]]></text>			</staticText>			<textField>				<reportElement x="161" y="79" width="107" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createHitOfTotal($F{entity},"selfStatement")]]></textFieldExpression>			</textField>						<staticText>				<reportElement x="61" y="99" width="100" height="20"/>				<textElement/>				<text><![CDATA[ignored Statements:]]></text>			</staticText>			<textField>				<reportElement x="161" y="99" width="107" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createIgnored($F{entity},"selfStatement")]]></textFieldExpression>			</textField>						<staticText>				<reportElement x="61" y="119" width="100" height="20"/>				<textElement/>				<text><![CDATA[Covered Branches:]]></text>			</staticText>			<textField>				<reportElement x="161" y="119" width="107" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createHitOfTotal($F{entity},"selfBranch")]]></textFieldExpression>			</textField>						<staticText>				<reportElement x="61" y="139" width="100" height="20"/>				<textElement/>				<text><![CDATA[ignored Branches:]]></text>			</staticText>			<textField>				<reportElement x="161" y="139" width="107" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createIgnored($F{entity},"selfBranch")]]></textFieldExpression>			</textField>			<subreport>				<reportElement x="50" y="0" height="300" width="500" isPrintWhenDetailOverflows="true" />				<dataSourceExpression><![CDATA[$P{DSFactory}.createBlockDS((MDVCoverageContainer)$F{entity})]]></dataSourceExpression>				<subreportExpression class="java.lang.String"><![CDATA["blockdetailsblock.jasper"]]>	</subreportExpression>			</subreport>		</band>	</detail>		</jasperReport>--------------- level 2 report ----------------------------------<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"  "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="BlockDetailReport">	<import value="com.cadence.mdv.reporting.ReportUtilities"/>	<queryString><![CDATA[select block from cc]]></queryString>	<field name="entity" class="com.cadence.mdv.model.MDVBlock" />			<detail>		<band height="300"   isSplitAllowed="true">									<textField>				<reportElement x="20" y="20" width="40" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[ReportUtilities.createHitOfTotal($F{entity},"count")]]></textFieldExpression>			</textField>											</band>	</detail>		</jasperReport>-----------  My data source ----------package com.cadence.mdv.reporting;import java.util.List;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;import net.sf.jasperreports.engine.JRRewindableDataSource;import com.cadence.mdv.api.IMDVDatasetServices;import com.cadence.mdv.model.MDVBaseEntity;import com.cadence.mdv.model.MDVListDataSet;import com.cadence.mdv.model.query.MDVSliceDefinition;import com.cadence.mdv.util.logging.MDVLogger;final public class DTOJRDataSource implements JRRewindableDataSource {    @SuppressWarnings("unused")    private static MDVLogger __logger = MDVLogger.getLogger(DTOJRDataSource.class);      private final MDVListDataSet      _data;    private final static int          SLICE_SIZE = 1000;    private int                       _index;    private int                       _sliceNum;    private List<MDVBaseEntity>       _slice;    private final IMDVDatasetServices _service;    public DTOJRDataSource(final MDVListDataSet data, final IMDVDatasetServices service) {        _data = data;        _service = service;        _slice = _service.getSlice(_data, new MDVSliceDefinition(0, SLICE_SIZE)).getEntities();        _index = 0;        _sliceNum = 0;    }    public Object getFieldValue(final JRField arg0) throws JRException {        return _slice.get(_index);    }    public void moveFirst() throws JRException {        _slice = _service.getSlice(_data, new MDVSliceDefinition(0, SLICE_SIZE)).getEntities();        _index = 0;        _sliceNum = 0;    }    public boolean next() throws JRException {        _index++;        if (_index >= _slice.size()) {            if (_slice.size() < SLICE_SIZE) {                return false;            }            _sliceNum++;            _slice = _service.getSlice(_data,                                       new MDVSliceDefinition(SLICE_SIZE * _sliceNum, SLICE_SIZE)).getEntities();            _index = 0;        }        return true;    }}
Link to comment
Share on other sites

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...