Jump to content

How to compile a subreport while the main report is executing ?


adasi

Recommended Posts

Hey.....

I have main report and 3 sub reports..when i compile the main report  there is an error..

net.sf.jasperreports.engine.JRException: Could not load object from location : .\Job_Card_subreport0.jasper

 

Can you put the code......

i used code.....

in Print Button...................

                Map params = new HashMap();
                params.put("JobCard",JobCardNo);
                new cls_Report().generateReport("Job_Card.jrxml", params);

in report class..........................

    String reportDir = "D:\\jobCardSys\\src\\Reports\\";     //C:\Users\Isuru\Desktop\report

    public  void generateReport(String reportname, Map params) throws JRException{

            JasperReport jr = JasperCompileManager.compileReport(reportDir + reportname);
            JasperPrint jp = JasperFillManager.fillReport(jr, params, new cls_Connect().connect());
            JasperViewer.viewReport(jp, false);
    
   }

sub reports in the same folder.....but can complier

help me!!!!!!!!!!!!

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I think you have a path / classpath problem. I prefer usually use relative path to my java main class than absolute.

sub reports can have their path relative to the main report that call them.

In some case I put the my reports files in a directory on wich I set in the class path even if is outside my jar distribution.

 

In my case I compile main & sub reports at runtime. But I use JRXML file and not .jasper because it allows me to redeliver report without regenering a complet application (data, properties, xml file are outside my distribution)

To do that :

// - Load & compile reports
// Master Report
InputStream inputStream = new FileInputStream(reportsRootDir + DIRECTORY + xxxx.jrxml);
JasperReport postTradeReport = JasperCompileManager.compileReport(inputStream);
inputStreams.add(inputStream);

// Title
inputStream = new FileInputStream(reportsRootDir + DIRECTORY + xxx.jrxml);
JasperReport reportTitle = JasperCompileManager.compileReport(inputStream);
inputStreams.add(inputStream);
.........

The input stream is only in my "Finaly" to close properly all my streams

My sub reports are parameters passed to my master report. So I can inject in my master report what ever sub report I want at runtime

//--------------------------------------
// - Report parameters
Map<String, Object> reportParameters = new HashMap<String, Object>();
....
// Title
reportParameters.put(ReportFieldNames.REPORT_TITLE, reportTitle);
// Overview
reportParameters.put(ReportFieldNames.REPORT_OVERVIEW, reportOverview);

......
After I have just to process report. My master report is only a template containing sub report. In future I think I can generate dynamically the master report and set my predefined jrxml files.

// Fill report
JasperPrint reportPrint = JasperFillManager.fillReport(postTradeReport, reportParameters, new JREmptyDataSource());
......

This was for java coding.

In your master report you must defined you subreport by jrxml file and sub reports are parameters of your master report.

<parameter name="report-title" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>

and define sub reports like this
<subreport isUsingCache="true">
<subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{report-title}]]></subreportExpression>

<subreportParameter .....>
.......
</subreportParameter>




</subreport>



Post Edited by neozerabbit at 09/15/2011 12:17
Link to comment
Share on other sites

 

InputStream inputStream = new FileInputStream(reportsRootDir + DIRECTORY + xxxx.jrxml);

must be........

FileInputStream inputStream = new FileInputStream(reportsRootDir + DIRECTORY + xxxx.jrxml);

 

there are some errors..when i put the java cording....

 

help me................

 

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