Sorting in iReport does not work with subreport?

0

Hi,

I have created three reports using XML DataSource. One is master report and two are  subreports. The main report has the date which needs to be sorted.  Without sorting,  the data in main report  including subreports are displayed correctly.  When specifying the date to be sorted in the main report, although date is not a parameter to be passed to subreports, the system gives this following error:

Error fillng print . . . Error evaluating expression:

. .  .Source text : ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//OSRpt"). . . . .

Caused by: java.lang.ClassCastException: net.sf.jasperreports.engine.fill.SortedDataSource cannot be cast to net.sf.jasperreports.engine.data.JRXmlDataSource

at OSRpt_1374067410320_765742.evaluate(OSRpt_1374067410320_765742:457)

at net.sf.jasperreprots.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)

. . . 19 more

Print not filled.  Try to use an EmptyDataSource

 
.... I couldn't find any answers out there.  Does any one have any suggestions on how to fix this problem?

Thank you very much!

 

 

phuongkimngo's picture
Joined: Jul 16 2013 - 10:45am
Last seen: 6 years 2 months ago

3 Answers:

0

I am having the exact same issue. I need to sort by a date in my main report but can't because I need to pull an items list through the use of a subreport. If anyone knows of a solution, I would love to hear it. I need to use this functionality quite often.

laura.willey's picture
Joined: Aug 14 2013 - 6:47am
Last seen: 6 years 3 months ago
0

Hi,

i also came across this issue when i tried to do this example:

http://community.jaspersoft.com/wiki/xml-datasources

The thing with the list and the following code worked at the beginning:
$P{REPORT_DATA_SOURCE}.subDataSource("/person/phone")

But when i add some sorting to the main report query, i also get this nasty "SortedDataSource cannot be cast to net.sf.jasperreports.engine.data.JRXmlDataSource" error.

I found this nasty workaround:
In the main report i created an additional field named "node" with "Field class" of "java.lang.Object" and as description "." (just a dot). This gets the actual org.w3c.dom.Node object.

Now the Dataset expression of the List component (-> dataset1):

new JRXmlDataSource(JRXmlUtils.createDocument($F{node}, true), "/person/phone")

To shorten this code i created two imports for this report:

net.sf.jasperreports.engine.data.JRXmlDataSource
net.sf.jasperreports.engine.util.JRXmlUtils

Hope this helps!

Actually i just found another (in my opinion better) way to do this. Here is it:

  1. Create a Field "node" of Field class "java.lang.Object" and use a dot (".") as description, just as described above.
  2. Now for the List component set it so that is does NOT use a Connection or DataSource. Instead provide a Reports map expression as of "REPORT_PARAMETERS_MAP" and additional set the parameter XML_DATA_DOCUMENT to
    JRXmlUtils.createDocument($F{node}, true)
  3. Now you can use the "Edit query" dialog of the dataset1 to enter you XPath expression, in this case "/person/phone"

I feared that this workaround would be quite slow compared to the normal subDataSource approach, but - here comes the good news - it's nearly as fast.

A look at the sources of net.sf.jasperreports.engine.data.JRXmlDataSource (http://grepcode.com/file/repo1.maven.org/maven2/net.sf.jasperreports/jas...) shows that the method subDataSource/subDocument do exactly the same.

Should also work quite well with sub reports.

Michael Schmid's picture
Joined: Oct 4 2013 - 9:43am
Last seen: 1 year 9 months ago
0

i've the same issue but i don't understand the solution...can you help me?

raffa74's picture
Joined: Jul 6 2013 - 7:58am
Last seen: 2 years 9 months ago
Feedback
randomness