Multiple Subreports in Main Report using same datasource -


i have main report 2 subreports. using custom datasource fetch report contents. 1 subreport gets displayed when main report previewed in jasper studio (whichever subreport comes first).

for eg. report1.jrxml gets displayed.if remove subreport report2.jrxml gets displayed.

main.jrxml

<detail>     <band height="250">         <subreport runtobottom="true">             <reportelement positiontype="float" x="0" y="130" width="1960" height="120" uuid="89a9f872-756e-4c82-922d-537cfde30cca"/>             <datasourceexpression><![cdata[$p{report_data_source}]]></datasourceexpression>             <subreportexpression><![cdata["report1.jrxml"]]></subreportexpression>         </subreport>     </band>     <band height="250">         <subreport runtobottom="true">             <reportelement positiontype="float" x="0" y="90" width="1960" height="120" uuid="892c0849-9532-48cb-94c0-f2e87528232a"/>             <datasourceexpression><![cdata[$p{report_data_source}]]></datasourceexpression>             <subreportexpression><![cdata["report2.jrxml"]]></subreportexpression>         </subreport>     </band> </detail> 

i have tried out following :

  1. placing subreports in different detail bands.
  2. setting "position type" "float".
  3. setting "run bottom" property "true".

the problem trying use same datasource multiple subreports. datasource gets exhausted first subreport , no data available subsequent sub reports.

solution :

you have rewind datasource using jrrewindabledatasource

thanks lucianc community answer

summarizing on tasks :

create wrapper rewindabledswrapper rewinds data source , delegates calls 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 custom data source class implement jrrewindabledatasource interface.

public void movefirst() throws jrexception {     // provide logic rewinding datasource } 

in jrxml file, if datasource custom 1 then

<datasourceexpression><![cdata[new com.jasper.api.rewindabledswrapper((jrrewindabledatasource)$p{report_data_source})]]></datasourceexpression> 

you cast report_data_source jrrewindabledatasource compiler try cast jrdatasource.

also add jar file containing rewindabledswrapper class classpath in studio.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -