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

JRDataSource and Crosstab


sergeleo

Recommended Posts

I have Crosstab report based on JRDataSource implementation. And when I was trying to put Crosstab into Details section, my report was always producing blank pages with no data... When I moved Crosstab into Summary section, my report comes out just fine, filled with data.

Based on logs my JRDataSource implementation always been called from Details and from Summary. But only when my Crosstab in Summary section, my report renders data.

I was looking through the forum and also I was googling for samples with implementation of the JRDataSource and Crossdab and so far I was able to find only few examples where Crosstab resides in Summary section. I wasn't able to find any example with JRDataSource and Crosstab in Detail section. So, is there any paerticular reason why it's not working? I'd like to take advantages of Page Headers and Footers in my report, but I can't unless I'll move my crosstab out of Summary...

Please share your experience!

Link to comment
Share on other sites

  • Replies 16
  • Created
  • Last Reply

Top Posters In This Topic

Yes, I'm using subdataset... And I'm getting 3 blank pages. I can see vertical lines for each row at the far right side of the page, but there is no data... Log4j shows that my JRDataSource implementation been called for each element... So, I'm pretty sure that report is filled with data. But PDF, CVS, XLS exporters return blank pages....

Link to comment
Share on other sites

If you use a subdataset for the crosstab, you need to pass in some data.  If the subdataset does not have a query, you'll need to pass a data source, as below

Regards,

Lucian

Code:
<datasetrun subDataset="..">  <datasourceexpression>..this is the data that I want the subdataset to iterate on..</datasourceexpression></datasetrun>

Post Edited by lucianc at 09/10/2009 16:58
Link to comment
Share on other sites

I made suggested change and now I have 15 blank pages /tools/fckeditor/editor/images/smiley/msn/whatchutalkingabout_smile.gif

 

((net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)$P{REPORT_DATA_SOURCE}).cloneDataSource()

Regards,

Serge




Post Edited by sergeleo at 09/10/2009 07:01 PM
Link to comment
Share on other sites

sergeleo
Wrote:

I made suggested change and now I have 15 blank pages /tools/fckeditor/editor/images/smiley/msn/whatchutalkingabout_smile.gif

 

((net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)$P{REPORT_DATA_SOURCE}).cloneDataSource()

Doing this doesn't make sense.

Let's say the report data source returns 20 records.  Then the detail band will be rendered 20 times.  Each detail band will contain a crosstab which will display the same data set.  So you'd end up with 20 identical crosstabs.

Having a crosstab in the detail band only makes sense if the data source used for the crosstab (via the subdataset) is different for each record in the report data source.

Why the crosstabs are empty I can't tell without seeing the data in your data source.

Regards,

Lucian

Link to comment
Share on other sites

sergeleo
Wrote:

How I can enable debugging for Jasper Reports?

What kind of debugging are you talkin about?

If you want debug logging, JR uses Commons Logging, so it depends on the logging library that you use.  For log4j for instance you would need to add log4j.logger.net.sf.jasperreports=debug to log4j.properties.  Note though that JR does not (yet) feature thorough debug logging.

If you want to do step-by-step debugging, download the JR sources and use any Java IDE to run your app in debug mode.

Regards,

Lucian

Link to comment
Share on other sites

All,

I finally  resolved my issue with placing Crosstab into Detail section. Maybe my workaround can go to FAQ ot Exmaples...

 

  1. I switched my code to use JasperFillManager.fillReport(JasperReport jasperReport, Map parameters ) method. I'm not passing DataSource through the method parameter.
  2. I'm passing my implementation of JRDataSource as a parameter JRParameter.REPORT_DATA_SOURCE.
  3. Also I created custom parameter "DynamicDataSource" and I'm passing same JRDataSource there.
  4. Inside of my template I defined subDataset and parameter for DynamicDataSource defined by class="net.sf.jasperreports.engine.JRDataSource"
  5. My crosstab placed into Detail section and datasetRun refering to pre-defined subDataset with dataSourceExpression referring to custom parameter "DynamicDataSource"

So, now my reports displays data in Detail section, and I can get advantage of  use pageHeader, pageFooter and all other sections.

 

Regards,

Serge

Code:
	protected JasperPrint fillJasperTemplate(JasperReport jasperReport,			JRDataSource dataSource) throws JRException {		// Preparing parameters		// Setting up virtualizer to have only 2 pages in memory and		// rest on file system		JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, System				.getProperty("java.io.tmpdir"));		Map<String, Object> parameters = new HashMap<String, Object>();		parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);		parameters.put(JRParameter.REPORT_DATA_SOURCE, dataSource);		parameters.put("DynamicDataSource", dataSource);		return JasperFillManager.fillReport(jasperReport, parameters);	}
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...