Jump to content

no data on all but first subreport


Go to solution Solved by lucianc,

Recommended Posts

Posted

Hi, I have a report with some groups and the detail band has a subreport which is printed each time group changes, always with the same datasource..

my problem is that I get no data for all but first printed subreport and I think it happens because the datasource is emptied when it's used.

here is the report:

please someone take some time to help me, I really need a little push..

thanks,
Pedro.

Post edited by: radix, at: 2007/01/10 12:19

Post edited by: radix, at: 2007/01/10 12:20
Post edited by: radix, at: 2007/01/10 14:13

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution
Posted

Not exactly sure how to help you. As you correctly assumed, filling a subreport exhausts the data source passed to it.

 

Bearing this in mind, you can either

  • provide a fresh data source each time the subreport gets filled, i.e. don't reuse the data source across subreport instantiations

if your subreport is rewindable (i.e. it implements JRRewindableDataSource), make sure that you rewind the data source before/after you use it once. You can do this, for instance, in one of the scriptlet's methods (like beforeDetailEval()).

combine the two previous approaches by writing a rewindable data source wrapper that rewinds a data source and delegates all the calls to it:

Code:

public class RewindableDSWrapper implements JRRewindableDataSource {
private final JRRewindableDataSource ds;
public RewindableDSWrapper(JRRewindableDataSource ds) {
this.ds = ds;
this.ds.moveFirst();
}
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();
}
}
-----
<subreport>
<dataSourceExpression>new RewindableDSWrapper(..subreport ds..)</dataSourceExpression>
</subreport>
[/ul]

 

HTH,

Lucian

Post edited by: lucianc, at: 2007/01/10 12:38

Posted

Lucian I just had another idea which I'm trying right now and consist in passing the datasource through a field to subreport..

 

It should be quick to try, I'll post some feedback.

 

If it fails I'll try your sugestion altough I found it a bit harder to do and since I'm a novice programmer it will take some more time to understand.

 

thanks,

Pedro.

 

ps: I also had to deface the screenshot cause my boss asked me to as this is an outsourcing project and our client shouldn't find that :)

Posted

Lucian my idea didn't work, I'm already trying to implement your sugestion, but I don't know where to define the Wrapper

 

thanks for your help,

pedro

Posted

Hi, I defined the RewindableDSWrapper class as you sugested, compiled it and put it into report directory.

 

 

Code:
import net.sf.jasperreports.engine.*;

public class RewindableDSWrapper implements JRRewindableDataSource
{
public final JRRewindableDataSource ds;

public RewindableDSWrapper(JRRewindableDataSource dsource)
{
this.ds = dsource;
try {
this.ds.moveFirst();
}catch(Exception e) {}

}

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();
}
}

 

 

as you can see I added the try-catch so I could compile it.

 

 

Then configured my main report to use that scriptlet class and configured the datasource expression of the sub report to:

Code:
[code]new RewindableDSWrapper($P{ds_detalhe_movimentos})

 

When I try to compile the report it gives these errors:

 

 

Code:
[code]Errors compiling .report_pages.jasper.
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The constructor RewindableDSWrapper(Object) is undefined
value = (net.sf.jasperreports.engine.JRDataSource)(new RewindableDSWrapper(((java.lang.Object)parameter_ds_detalhe_movimentos.getValue())));

 

 

I don't know if it is because my default datasource is not a RewindableDataSource and it cannot cast it.

 

someone gimme a little help..

 

thanks,

pedro

 

Post edited by: radix, at: 2007/01/10 19:06

Post edited by: radix, at: 2007/01/10 19:07

Posted

First of all, is your subreport data source a JRRewindableDataSource or not? You should know this before trying this solution.

 

The error is caused by the fact that you've declared the ds_detalhe_movimentos parameter as java.lang.Object. For the report to compile, you'll have to either declare it as net.sf.jasperreports.engine.JRRewindableDataSource (or a class/interface that extends it), or cast the parameter value yourself in the data source expression:

Code:

<dataSourceExpression>new RewindableDSWrapper((JRRewindableDataSource) $P{ds_detalhe_movimentos})</dataSourceExpression>

 

HTH,

Lucian

Posted

It wasn't a Rewindable Datasource, but it is now.

All my datasources Extend this Template class

 

Code:
public abstract class Template implements JRRewindableDataSource{	

/* VARIAVEIS PRIVADAS */
/**
* Current index of the result set
*/
protected int index = -1;
.
.
.
public boolean next() throws JRException{
index++;
return (index < hashmap.size());
}

public void moveFirst() throws JRException{
index = -1;
}

 

I declared the Parameter 'ds_detalhe_movimentos' as

Code:
[code]net.sf.jasperreports.engine.JRRewindableDataSource
set it to 'Use as a prompt' and set the datasource expression to
Code:
[code]new RewindableDSWrapper((JRRewindableDataSource) $P{ds_detalhe_movimentos})

 

the report has now compiled but I get this Error when I run the app on eclipse:

 

 

this parts of the error should tell you what is happening (complete error on the end)

Code:
[code]Error loading scriptlet class : RewindableDSWrapper
at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:582)

 

Code:
[code]Caused by: java.lang.ClassNotFoundException: RewindableDSWrapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

 

 

complete error:

Code:
[code]Exception in thread "main" net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error loading scriptlet class : RewindableDSWrapper
at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:582)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:343)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:311)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:275)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVerticalFiller.java:292)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:201)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:109)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:751)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:679)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfFile(JasperRunManager.java:349)
at controller.CntrFormatter.initFormatter(CntrFormatter.java:228)
at initiation.Main.main(Main.java:24)
Caused by: net.sf.jasperreports.engine.JRException: Error loading scriptlet class : RewindableDSWrapper
at net.sf.jasperreports.engine.fill.JRFillDataset.createScriptlet(JRFillDataset.java:452)
at net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:592)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:702)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:679)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:499)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:63)
at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:137)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassNotFoundException: RewindableDSWrapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:90)
at net.sf.jasperreports.engine.fill.JRFillDataset.createScriptlet(JRFillDataset.java:447)
... 8 more

 

 

thanks for your patience.. your help is being precious..

 

pedro.

Post edited by: radix, at: 2007/01/11 09:16

Posted

I've just tryied to define this:

 

Code:
public void beforeDetailEval() throws JRScriptletException
{
(net.sf.jasperreports.engine.JRRewindableDataSource)getParameterValue("ds_detalhe_movimentos"«»).moveFirst()
}
/** end EVENT_BEFORE_DETAIL_EVAL Please don't touch or move this comment*/

 

on internal scriplet editor ant set report to use internal support and changed the data source expression to just

 

Code:
[code]$P{ds_detalhe_movimentos}

 

but I get this error when compiling the report:

 

 

Code:
[code]Compiling scriptlet source file... C:Documents and SettingsPedro_M_D_CatalaoDesktopnovos_layouts_gruposreport_pagesScriptlet.java
Error compiling the Scriptlet Java source.
net.sf.jasperreports.engine.JRException:ÂErrorÂcompilingÂreportÂjavaÂsourceÂfilesÂ:ÂC:DocumentsÂandÂSettingsPedro_M_D_CatalaoDesktopnovos_layouts_gruposreport_pagesScriptlet.java ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:119) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRAbstractMultiClassCompiler.compileClass(JRAbstractMultiClassCompiler.java:45) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:327) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) CausedÂby:Âjava.lang.ClassNotFoundException:Âcom.sun.tools.javac.Main ÂÂÂÂatÂjava.net.URLClassLoader$1.run(UnknownÂSource) ÂÂÂÂatÂjava.security.AccessController.doPrivileged(NativeÂMethod) ÂÂÂÂatÂjava.net.URLClassLoader.findClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂsun.misc.Launcher$AppClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClassInternal(UnknownÂSource) ÂÂÂÂatÂjava.lang.Class.forName0(NativeÂMethod) ÂÂÂÂatÂjava.lang.Class.forName(UnknownÂSource) ÂÂÂÂatÂnet.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:90) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:81) ÂÂÂÂ...Â3Âmore

 

it does not matter much how it's done.. the first way that works is the one for me :)

 

thanks.

Posted

it gives me the same error if I don't define anything on scriptlet editor but the option to use internal scriptlet support is selected

 

hope it helps

Posted

I managed to work it out redefining the next() method for my reusable datasource like this:

 

Code:
	public boolean next() throws JRException{
index++;
boolean teste = (index < hashmap.size());
if(!teste)index = -1;
return teste;
}

 

it works :)

 

btw, in this case do I need to declare my Datasources as Rewindable ?

 

thanks for the help,

pedro

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