Does a subreport with a parameter indicating a web service json source still need a datasource from main report

0

Lords and Ladies,

I have a report that uses a parameter to get its json data:

<parameter name="net.sf.jasperreports.json.source" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["http://34.208...."&docType=" + $P{docType}]]></defaultValueExpression>
    </parameter>

It works great on its own, it is autonomous ( not having a data adaptr).

However, I want to use it as a subreport. Do I need to give it a datasource ? and if so, will it cause probleme since it goes fetching one itself ? (I am passing master report parameters_map)

Thanks in advance

pierre.ortalo's picture
Joined: Aug 16 2017 - 1:34am
Last seen: 1 year 4 months ago

2 Answers:

0

Ok, I got it :)

So, it seems that giving a datasource to the subreport in the main report design is mandatory.

The called subreport doesn't perform it's own rest service datasource call.

In order to work I used the following datasSource expression for the subreports:

new net.sf.jasperreports.engine.data.JsonDataSource("http://34....Id=" + $P{Id}.toString(), "")

It creates a JSONDatasource object by calling its constructor and passes the url where to get the json (location argument of the constructor) , second argument is a query on returned data. A main report argument can be passed to the url as you can see.

Hope it helps anyone :)

pierre.ortalo's picture
Joined: Aug 16 2017 - 1:34am
Last seen: 1 year 4 months ago
0

@pierro  Please provide full source files in zip please.so that i can check how you used main report and sub report to achieve this.

sushobhan.b's picture
Joined: Aug 22 2018 - 10:52pm
Last seen: 1 week 6 days ago
Feedback