Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

java - JasperReports: Can't locate subreport

It's drives me crazy.. Last hour I am trying to figure out why my report stopped to worked right after I added a subreport to it.. I already checked and tried all similar issues here, here and here. Without success.. Subreport is in the same directory for sure.. The definition looks like:

<subreport isUsingCache="false">
                <reportElement uuid="db816b3c-a13d-440f-a6a2-f899762e61e4" x="0" y="89" width="555" height="100"/>
                <subreportParameter name="footerAddress">
                    <subreportParameterExpression><![CDATA[$P{footerAddress}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerManager">
                    <subreportParameterExpression><![CDATA[$P{footerManager}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerContact">
                    <subreportParameterExpression><![CDATA[$P{footerContact}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerBank">
                    <subreportParameterExpression><![CDATA[$P{footerBank}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{SUBREPORT_DIR}]]></subreportExpression>
            </subreport>

Where $P{SUBREPORT_DIR} is "/valid/path/sub.report.jasper"

And I still getting an error: Resource not found at /valid/path/sub.report.jasper

WHY??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In first message author says:

Where $P{SUBREPORT_DIR} is "/valid/path/sub.report.jasper"

$P{SUBREPORT_DIR} is a directory, but not a filename. It is the first error.

The second: sometimes jasper can't find subreport, even the path is correct.

The way for solving this problem:

  1. Pass $P{SUBREPORT_DIR} into main report (In this case: "/valid/path/"), put this parameter into a HashMap<String, Object> - standard way pass parameters into jasper.
  2. Pass $P{SUBREPORT_DIR} from main report into subreport as parameter: $P{SUBREPORT_DIR} main report -> $P{SUBREPORT_DIR} of subreport (this way used when exist subsubreport, which calling from subreport)
  3. In main report set expression to subreport as $P{SUBREPORT_DIR} + "sub.report.jasper"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...