Jump to content

Data not showing in main report after running a subreport


ignacio.coca

Recommended Posts

Hi all.

I have now another issue related to subreports in JasperStudio.

I have in my main report some groups displaying my data ok. The data is shown in 5 detail sections, one for each group header (my report must have seven different sections).

In the sixth section I need to use a subreport. I use the subreport in the 6th group header, and it is displayed OK. I can see the detail sections from 1 to 5, and the subreport.

The problem comes when I put data into the 7th detail section. Basically, it does not display nothing. It seems that the subreport has used all the rows of my CSV and the main report has no more data.

If I delete the subreport in the 6th group, I can see the data in the 7th one, so I am sure that the problem is the subreport.

What can I do?

Thank you!!

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I found this problem in another forum, where the solution is given, but I do not understand it.

 

It says:


//----------------

Solution :

You have to rewind the datasource using JRRewindableDataSource

Thanks to lucianc Community answer

Summarizing on the tasks :

Create a wrapper RewindableDSWrapper that rewinds a data source and delegates all the calls to it.


     package com.jasper.api;

     import net.sf.jasperreports.engine.JRException;
     import net.sf.jasperreports.engine.JRField;
     import net.sf.jasperreports.engine.JRRewindableDataSource;

     public class RewindableDSWrapper implements JRRewindableDataSource {

     private final JRRewindableDataSource ds;

     public RewindableDSWrapper(JRRewindableDataSource ds) {

       this.ds = ds;

       try {
         this.ds.moveFirst();
         } catch (JRException e) {
            e.printStackTrace();
            }

       }

     public boolean next() throws JRException {
       return ds.next();
       }

     public Object getFieldValue(JRField jrField) throws JRException {
       return ds.getFieldValue(jrField);
       }

     public void moveFirst() throws JRException {
       ds.moveFirst();
       }

     }


In your custom data source class implement JRRewindableDataSource interface.

    public void moveFirst() throws JRException {
    // provide logic for rewinding datasource
    }

In your jrxml file, if your datasource is custom one then

    <dataSourceExpression><![CDATA[new com.jasper.api.RewindableDSWrapper((JRRewindableDataSource)$P{REPORT_DATA_SOURCE})]]></dataSourceExpression>

you cast REPORT_DATA_SOURCE to JRRewindableDataSource as the compiler will try to cast it to JRDataSource.

Also add the jar file containing RewindableDSWrapper class to classpath in your studio.

----------------//

The problem is that I don't know how to implement this in my report. Where must I write all this code?

Thank you!!

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