tubamanu Posted March 3, 2009 Share Posted March 3, 2009 Hi,i'm using JasperReport and iReport to create an order list out of an XML File. Every order has several articles, sometimes 1 or sometimes more then 5. Acutally my problem is, that my subreport displays for every order item, all artciles listet in the XML File. For exampleOrder1 Article 1 Article 2 Article 3Order2 Article 1 Article 2 Article 3but in xml, Order1 has only 2 Artciles an Order2 has only 1 article. I think my problem is that theres a mistake passing the paramter from my masterreport to my subreport. But i dont find my mistake. I will add my java, jrxml and xml source file. maybe someone can have a look.....thx! Code:Java File:import java.io.File;import java.util.HashMap;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRXmlDataSource;public class mySubTemplate { public static void main(String[] args) { JasperReport jasperReport; JasperPrint jasperPrint; HashMap<String, String> parameter = new HashMap<String, String>(); try { JasperCompileManager.compileReportToFile("template/reportTemplate.jrxml","template/reportTemplate.jasper"); JasperCompileManager.compileReportToFile("template/reportSubTemplate.jrxml","template/reportSubTemplate.jasper"); } catch (JRException ex) { ex.printStackTrace(); } try { JRXmlDataSource xml = new JRXmlDataSource(new File("data/testData.xml"), "/list/order/packst"); jasperReport = JasperCompileManager.compileReport("template/reportTemplate.jrxml"); jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, xml); // pdf output JasperExportManager.exportReportToPdfFile(jasperPrint, "output_sub.pdf"); } catch (JRException e) { e.printStackTrace(); } }}Post Edited by Manu Smith at 03/03/09 10:46 Link to comment Share on other sites More sharing options...
ro281815 Posted March 3, 2009 Share Posted March 3, 2009 You have to pass your parameter in your connection string for the subreport, something like this should solve your problem: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/list/orderarticle/article/[packstnumber = '"+$F{packstnumber}+"']") Also I noticed in the subreport you have this path: list/orderarticle/article/[packstnumber = '$F{packstnumber}'] Shouldn't you be passing the parameter in as $P{packstnumber} and not as a field? I don't have an xml file to test it on. it just looks wrong to me. Link to comment Share on other sites More sharing options...
kalevisiren Posted March 3, 2009 Share Posted March 3, 2009 I have also been trying to get simple master + subreport combination to work. All samples I've found at JasperForge show how to do this with older versions of iReport.Could someone please write a concise sample of subreport implementation and put it to this forum. I believe that I'm not the only one who is trying to solve this.Regards and thanks,Kalevi Link to comment Share on other sites More sharing options...
tubamanu Posted March 3, 2009 Author Share Posted March 3, 2009 thx for your help!i don't know if it is correct to use Fields instead of paramter. I've changed subreport tag ( see Code ) but i get when i try to compile, i get these errors......i also don't know, how to use a paramter instead of an field....:( EDIT: i've taken an example from jasperreports-3.1.4demosamplesxmldatasource...here is used a field to transfer a key date to the subreport thx 4 help! log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).log4j:WARN Please initialize the log4j system properly.net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/list/orderarticle/article/[packstnumber = '"+$F{packstnumber}+"']") at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:197) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:574) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:542) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:835) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:341) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:261) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:888) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:810) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at mySubTemplate.main(mySubTemplate.java:37)Caused by: net.sf.jasperreports.engine.JRException: XPath selection failed. Expression: /list/orderarticle/article/[packstnumber = '1'] at net.sf.jasperreports.engine.util.xml.XalanXPathExecuter.selectNodeList(XalanXPathExecuter.java:62) at net.sf.jasperreports.engine.data.JRXmlDataSource.moveFirst(JRXmlDataSource.java:263) at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:178) at net.sf.jasperreports.engine.data.JRXmlDataSource.dataSource(JRXmlDataSource.java:388) at report32name_1236090252694_94507.evaluate(report32name_1236090252694_94507:206) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:186) ... 16 moreCaused by: javax.xml.transform.TransformerException: Nach dem Token '/' oder '//' wurde ein Positionsschritt erwartet. at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:602) at org.apache.xpath.compiler.XPathParser.RelativeLocationPath(XPathParser.java:1579) at org.apache.xpath.compiler.XPathParser.LocationPath(XPathParser.java:1537) at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1259) at org.apache.xpath.compiler.XPathParser.UnionExpr(XPathParser.java:1178) at org.apache.xpath.compiler.XPathParser.UnaryExpr(XPathParser.java:1084) at org.apache.xpath.compiler.XPathParser.MultiplicativeExpr(XPathParser.java:1005) at org.apache.xpath.compiler.XPathParser.AdditiveExpr(XPathParser.java:947) at org.apache.xpath.compiler.XPathParser.RelationalExpr(XPathParser.java:872) at org.apache.xpath.compiler.XPathParser.EqualityExpr(XPathParser.java:812) at org.apache.xpath.compiler.XPathParser.AndExpr(XPathParser.java:776) at org.apache.xpath.compiler.XPathParser.OrExpr(XPathParser.java:749) at org.apache.xpath.compiler.XPathParser.Expr(XPathParser.java:732) at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:125) at org.apache.xpath.XPath.<init>(XPath.java:162) at org.apache.xpath.CachedXPathAPI.eval(CachedXPathAPI.java:276) at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:209) at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:189) at net.sf.jasperreports.engine.util.xml.XalanXPathExecuter.selectNodeList(XalanXPathExecuter.java:60) ... 21 more Code: Post Edited by Manu Smith at 03/03/09 14:37 Link to comment Share on other sites More sharing options...
tubamanu Posted March 3, 2009 Author Share Posted March 3, 2009 Okay , I've found a solution. I will add Master and Subreport Templates here, and my XML Data Source If someone is interested write PMthx everyone 4 help! Code: Post Edited by Manu Smith at 03/03/09 14:57 Link to comment Share on other sites More sharing options...
ro281815 Posted March 5, 2009 Share Posted March 5, 2009 Is it working yet? Could you attach the xml file. I always use parameters but if it works using fields then that's fine. Link to comment Share on other sites More sharing options...
ro281815 Posted March 5, 2009 Share Posted March 5, 2009 never mind i just saw the xml under "Code" Link to comment Share on other sites More sharing options...
ro281815 Posted March 5, 2009 Share Posted March 5, 2009 Does your subreport work by itself. I'm having a problem interpreting your path. This:/list/orderarticle/article/[packstnumber = '$F{packstnumber}'] doesn't work in my xml editor. Link to comment Share on other sites More sharing options...
ro281815 Posted March 5, 2009 Share Posted March 5, 2009 The xml code didn't work for me either so please attach the working xml file. I think the path u need is: /list/orderarticle/article[packstnumber = '$F{packstnumber}'] This path works in my xml editor but what you had originally did not work and is one of the causes of the error you are showing. So if you attach the working xml file I'll be able to debug your parameter issue better.Post Edited by Rodyna Zidan at 03/05/09 18:57 Link to comment Share on other sites More sharing options...
jbo_master Posted May 29, 2009 Share Posted May 29, 2009 Here is a working sample of a report using a subreport element.You have to create a new xml datasource which points to the attached xml-file.report_main.jrxml: You have to change the "Default Value Expression" of the "SUPREPORT_DIR" Parameter. This Parameter defines the path to your subreport. For Example "C:\\temp\\"By the way:The correct xPath expression for the main report is: /list/order/packstThe correct DataSource expression for feeding the subreport with values is: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/list/orderarticle/article[packstnumber = '"+ $F{packstnumber} +"']")Have a nice day Post Edited by jbo_master at 05/29/2009 07:02 Link to comment Share on other sites More sharing options...
kj259 Posted June 9, 2009 Share Posted June 9, 2009 Where can I find worked example of Master/Detail and Parmeter Passing in iReports 3.5.2KJ259 Link to comment Share on other sites More sharing options...
klingela Posted July 6, 2009 Share Posted July 6, 2009 This example compiles and runs successfully, but it generates 0 pages. It doesn't generate anything when supplied with a "1" or a "2" for the parameter prompt.######### UPDATE #######I DID get this to generate data, I had a problem in the data source I set up for the example, which I fixed######################### This is kind of a funny XML file to show for an example. This XML file is set up with Master/Detail relationships. Most XML files have the entire hierarchy built into each element. The structure of this example is: <order> <packstr/> <packstr/> <packstr/></order><orderarticle> <article/> <article/> <article/> <article/></orderarticle> You are much more likely to see:<order> <packstr> <orderarticles> <article/> <article/> <article/> <article/> </orderarticle></order>in which case I guess you'd need to provide a subDataSource rather than a dataSource. But I don't know, because there's almost zero documentation and the Definitive Guide book examples are incorrect. Trial and error is proving to be extremely difficult to troubleshoot this problem. I do appreciate your effort though. My main problem is that I get a runtime exception "ClassCastException" for the subdatasource I create with the following line:((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/Master/Sub") I've tried pretty much everything, and it will not progress beyond that ClassCastException.Post Edited by klingela at 07/06/2009 20:16 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now