views:

131

answers:

2

Hi Experts,

I am using iReport with JasperReports 1.3.4.

A master report contains two subreports, one of which has a subreport. All .jasper files are in the same directory.

iReport generated a SUBREPORT_DIR parameter. The subreportExpression gives the subreport filename as ![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"].

Everything works when run within iReport.

The Java web application to generate reports receives a SUBREPORT_DIR parameter by calling JasperFillManager.fillReport(String sourceFileName, Map parameters, JRBeanCollectionDatasource). The SUBREPORT_DIR is set to the master report's directory.

The fillReport method throws an exception:

net.sf.jasperreports.engine.JRException: Could not load object from location : .sub-subreport.jasper.

The first subreport seems to process its subreport(embedded subreport), but SUBREPORT_DIR is not being used to generate the name of the sub-subreport.

What am I missing? How should this scenario be handled?

Thank you.

Update

In the Java class:

filepath = request.getSession(true).getServletContext().getRealPath("/jsps/jrxmls/");
param.put("SUBREPORT_DIR",filepath);

If I change it to the empty string (""). then it will pass null value right?

My report structure is like:

 MasterReport -> Subreport1 -> Sub-Subreport1

The problem is not able to load "Sub-Subreport1".

A: 

From the exception message it seems that you are using a "." as the SUBREPORT_DIR parameter. If so, try using "./" or just "."

gedim
where to put "./" ? i am confusing
Manu
Right now I suppose that you are using: parameters.put("SUBREPORT_DIR", ".");JasperFillManager.fillReport(String sourceFileName, Map parameters, JRBeanCollectionDatasource);Try using:parameters.put("SUBREPORT_DIR", "");
gedim
In java class Param, i am setting param like ..param.put("SUBREPORT_DIR",filepath) where filepath =request.getSession(true).getServletContext().getRealPath("/jsps/jrxmls/") . as per your advice how can i change it to "".then it will pass null value right?
Manu
It will pass an empty String value. That will make the master reports look for their subreports in their current path. Also, are your .jasper files in the same folder of your .jrxml files?
gedim
@Gedim..see my edited part also..
Manu
yes all my .jrxm and .jasper files on same folder.
Manu
@Gedim.. after changing param to "./" it giving error like "JRException:Report Generation Exception: net.sf.jasperreports.engine.JRException: Could not load object from location : ./Collateral_Subreport1.jasper" ... now it is not loading the first "subreport1" also
Manu
One easy solution would be to remove the ${SUBREPORT_DIR} parameter completely and use the ![CDATA["subreport.jasper"] expression for your subreports.
gedim
can you give me some sample code.. i am totally frustrated on this issue.
Manu
@Gedmin... atlast i fixed ..i directly fetch context root in jsp page and pass to jasper through bean field...
Manu
thanks for your support...
Manu
+1  A: 

Click in 'Subreport1', go to the properties tab -> Subreport properties -> Parameters

You will pass your 'MasterReport' SUBREPORT_DIR parameter as a parameter to 'Subreport1'. Create this entry:

Name: SUBREPORT_DIR Expression: $P{SUBREPORT_DIR}

Don't forget to recompile your reports and make sure to republish your web app in the application server.