Jump to content
We've recently updated our Privacy Statement, available here ×

Can't undestand why this won't work with subreports


bthale

Recommended Posts

We are using a framework that we have written that makes it hard to pass in a data source for a subreport. So I created a variable of type JRBeanCollectionDataSource. I have a scriptlet that overrides beforeDetailEval. See code below:

When I set a break point in this method, I can see the correct data being retrieved and passed to the variable, but debug console outpupt shows no data being passed and subreport is empty. What could cause this behaviour? The jrxml specific code is here.

<variable name="SUB_REPORT_DATA_SOURCE" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>     

<subreport>
    <reportElement x="0" y="9" width="802" height="41"/>
    <dataSourceExpression><![CDATA[$V{SUB_REPORT_DATA_SOURCE}]]></dataSourceExpression>
    <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "TradeUpdatesSubreport.jasper"]]></subreportExpression>
   </subreport>
 

 

 

Code:
    public void beforeDetailEval() throws JRScriptletException    {	JRBeanCollectionDataSource ds = (JRBeanCollectionDataSource)this.getParameterValue("REPORT_DATA_SOURCE");	this.setVariableValue("SUB_REPORT_DATA_SOURCE", ds);    }

Post Edited by bthale at 04/04/2011 20:48
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi,

 

Sub reports are evaluated before code you've provided.

So first data source (which is empty or null at that moment) is passed to subreport and only after it is populated during beforeDetailEval() execution.

 

Why you not use pure report parameter for your data source, populate it on back-end of your application and then simply pass it to sub report?

 

Best,

Taras

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