.jasper from database and subreport expression

 

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?


fachhoch's picture
129
Joined: May 1 2009 - 8:23am
Last seen: 9 years 1 month ago

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 .

 

fachhoch's picture
129
Joined: May 1 2009 - 8:23am
Last seen: 9 years 1 month ago

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>
lucianc's picture
76744
Joined: Jul 17 2006 - 1:10am
Last seen: 6 hours 17 min ago

Thank you for your reply.It worked. now a new doubt,   with this approach   can I test my reports with preview button using Ireport ?

 

the problen is how can I tell Ireport about the SubreportsMap    parameter ?

 



Post Edited by fachhoch at 02/05/2010 13:31
fachhoch's picture
129
Joined: May 1 2009 - 8:23am
Last seen: 9 years 1 month ago

I don't think there's a way to have that working in iReport.  You can post the question on the iReport though.

Regards,

Lucian

lucianc's picture
76744
Joined: Jul 17 2006 - 1:10am
Last seen: 6 hours 17 min ago

 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>
cyberoblivion's picture
Joined: Apr 22 2011 - 3:53am
Last seen: 2 years 10 months ago
I got it working. just didn't have classpath jars set to reloadable
cyberoblivion's picture
Joined: Apr 22 2011 - 3:53am
Last seen: 2 years 10 months ago
What is the jaspersubreport expression you used for this?
thebigr's picture
31
Joined: Nov 17 2010 - 3:24pm
Last seen: 12 years 6 months ago

com.ciminc.compass.util.ReportUtil.fetchReportByName($P{REPORT_CONNECTION},"collageCommonHeader")

cyberoblivion's picture
Joined: Apr 22 2011 - 3:53am
Last seen: 2 years 10 months ago
Feedback
randomness