Jump to content
  • Detail from Subreport not appearing when using xpath on main and subreport


    robertwilkinson
    Assigned User teodord
    CategoryBug report
    PriorityHigh
    ReproducibilityAlways
    ResolutionNo Change Required
    SeverityMajor
    StatusClosed

    I am trying to produce a subreport using xpath on an XMl file for the main report and the same xml file with a different xpath for the subreport.

     

    No matter what I try I do not seem to be able to get the subreports detail lines to appear. I have created a minimal case and precluded any parameter issues, content to have all the subreport details appear at every main report detail line for now.

     

    Viewed standalone the subreport works fine so I am hopeful it isn't an xpath issue.

     

    It works fine for SQL data but not for my xpath.I have tried everything I know for over a week now and am hopeful that I can get some help.



    User Feedback

    Recommended Comments

    You need to pass the XML_DATA_DOCUMENT parameter (used by the XPath query executer) to the subreport. See demo/samples/xmldatasource for a working example.

     

    Regards,

    Lucian

    Link to comment
    Share on other sites

    Thanks for the response, Lucian.

     

    I was using iReport and the data source is in fact specified in the subreport xml document as follows:-

     

    ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/MemberShipList/Member/Guests/Guest")

    $P{SUBREPORT_DIR} + "MemberUsage_guest.jasper"

     

    Your reference to the sample was for a code generated report. if I were confident I could get it that way rather than using iReport then I would forget iReport and go straight there but I need to test it first using iReport. It is iReport that doesn't seem to work.

     

    Regards,

    Rob

    Link to comment
    Share on other sites

    I didn't see a dataSourceExpression in the test case that you attached. There are two ways of using XML files as data, you can either write XPath queries in the reports or directly instantiate JRXmlDataSource instances. You need to decide on one approach and use it consistently in the reports.

     

    You can gain confidence that the samples work by running them.

     

    Regards,

    Lucian

    Link to comment
    Share on other sites

    Sorry to be a pest, Lucian and thanks for your patience.

     

    In iReport there is a subreport wizard. On the first screen of that wizard I use an existing connection.

     

    On the second screen of that wizard I specify use the same connection as used to fill the master report.

     

    I then give it the parameters.

     

    Is that not the correct approach for iReport?

     

    regards,

    Rob

    Link to comment
    Share on other sites

    I think I finally see the disconnect and what causes the confusion.

     

    In the wizard there is a radio button that says "use the same connection used to fill the master report".

     

    Because I used the same "datasource" for both the master and sub reports I checked this button but it is in fact speaking to a SQL connection and not a data source. So you were correct I did not have a datasource properly set. The information presented in the wizard is somewhat misleading to a neophyte,

     

    However now I do and try as I may I still cannot get any detail lines to print in the subreport.

     

     

    Link to comment
    Share on other sites

    I have resolved the problem and so am leaving a final note to help all those who come after me.

     

    Thank you for your help Lucian. You gave me the spark to start the debugging session.

     

    Using an XML Datasource and xpath with the same datasource in both the main report is not a simple or intuitive task when using iReport. So to help others.

     

    1. You must not use the same XMLDataSource for both the main and subreport. JRXmlDataSource increments pointers and so if you use the same source for both main and sub it will inevitably get lost.

     

    2. The best way to get the subreport datasource is to use the main report source but the datasource method of JRXmlDataSource. Example:- ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("//Guest[ancestor::Member/@MemberID="+$F{MemberID}+"]").

     

    3. Do not simply use the wizard and select "Use the same connection used to fill the master report." This is only for SQL connections.

    Link to comment
    Share on other sites


×
×
  • Create New...