If I transfer the .jasper from database into a object instance at startup , so the . jasper is not in filesytem but it is in memory, in an instance object , and this report uses sub-report and this also gets loaded into an object instance ,
till now I was placing my .jasper inside my jar file , so I used the subreport expression
<subreportExpression class="java.lang.String"><![CDATA["com/tnt/acf/document/ClearanceDocument_1.jasper"]]></subreportExpression>
if the subreport is not in a package and is within an object instance , what should be the subreport expression?
8 Answers:
Ok I will put in other words.
My reports have subreports , any report with subreport have to tell where to find subreport.
In my case all my compiled jasper objects are in a HashMap . Please tell me what should be the subreport expression?
I have Report A and a subreport B
In A I have to provide subreport expression to find B please tell me what should the expression for B .
Pass the subreport map to the master report and use something like below.
Regards,
Lucian
Code: |
<subreportExpression class="net.sf.jasperreports.engine.JasperReport">(net.sf.jasperreports.engine.JasperReport) $P{SubreportsMap}.get("Subreport Key")</subreportExpression></td></tr></tbody></table> |
I am trying to do a similar thing. I want to use a public static java method to retrieve the jasper subreport so in my value expression for the subreport I have
com.ciminc.compass.util.ReportUtil.fetchReportByName($P{REPORT_CONNECTION},"collageCommonHeader")
the expression class is set to java.io.inputstream. the connection when previewing is null though.
The reason for this approach is that I don't want the servlet who executes the report to have to know about what subreports the report needs... Is this reasonable?
the fetch code looks like this
Code: |
public static InputStream fetchReportByName(Connection con, String contextReportName) { PreparedStatement stat = null; ResultSet rs = null; try { stat = con.prepareStatement("Select JASPER_REPORT from Context_Report where REPORT_NAME = ?"); stat.setString(1, contextReportName); rs = stat.executeQuery(); byte[] reportBytes = null; if (rs.next()) { Blob b = rs.getBlob(1); reportBytes = b.getBytes(1L, (int) b.length()); } return new ByteArrayInputStream(reportBytes); } catch (SQLException ex) { System.out.println("error getting sub report " + contextReportName); ex.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) { } } if (stat != null) { try { stat.close(); } catch (SQLException ex) { } } } return null; }</td></tr></tbody></table> |