bernardopina Posted May 3, 2010 Share Posted May 3, 2010 Hey guys,I have a servlet that receives two parameters: Report Name (example.jrxml) and a xml (on text, not on a file). The servlet have to return a compiled report on .pdf extension.The problem is that i am configuring the XPath within the .jrxml, but the report is not being generated correctly. The report is generated only with the first node of three of the XML.See the files attached for more info.Any clue? Thanks!Post Edited by bernardopina at 05/03/2010 19:37 Link to comment Share on other sites More sharing options...
pablodc Posted May 4, 2010 Share Posted May 4, 2010 Hi, The fields XPath expressions are wrong. You have: <field name="nome" class="java.lang.String"> <fieldDescription><![CDATA[/funcionarios/funcionario/nome]]></fieldDescription> </field> <field name="matricula" class="java.lang.String"> <fieldDescription><![CDATA[/funcionarios/funcionario/matricula]]></fieldDescription> </field> <field name="cargo" class="java.lang.String"> <fieldDescription><![CDATA[/funcionarios/funcionario/cargo]]></fieldDescription> </field> Try with: <field name="nome" class="java.lang.String"> <fieldDescription><![CDATA[nome]]></fieldDescription> </field> <field name="matricula" class="java.lang.String"> <fieldDescription><![CDATA[matricula]]></fieldDescription> </field> <field name="cargo" class="java.lang.String"> <fieldDescription><![CDATA[cargo]]></fieldDescription> </field> You can change the fields XPath from its properties in the IDE.Good luck!grettings from Argentina! Link to comment Share on other sites More sharing options...
bernardopina Posted May 4, 2010 Author Share Posted May 4, 2010 Unfortunately i have already tried that with no success. When i do what you said, i just got "null" on every field, and still just one register instead of 3. =/ Link to comment Share on other sites More sharing options...
lucianc Posted May 4, 2010 Share Posted May 4, 2010 When you have an XPath query in the report, you should fill the report by passing a org.w3c.dom.Document value for the JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT parameter, as below.Is that what you are doing?Regards,LucianCode:parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, JRXmlUtils.parse(xmlFile));JasperPrint print = JasperFillManager.fillReport(report, parameters); Link to comment Share on other sites More sharing options...
bernardopina Posted May 4, 2010 Author Share Posted May 4, 2010 I made this with still no success:Code:HashMap parameters = new HashMap(); JasperDesign jasperDesign = JRXmlLoader.load(xmlString); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, JRXmlUtils.parse(xmlString)); print = JasperFillManager.fillReport(jasperReport, parameters, ds); Link to comment Share on other sites More sharing options...
lucianc Posted May 5, 2010 Share Posted May 5, 2010 Don't pass a data source when you have a query in the report.HTH,Lucian Link to comment Share on other sites More sharing options...
bernardopina Posted May 5, 2010 Author Share Posted May 5, 2010 I have already tried to remove the DataSource from the call, and the code became this:print = JasperFillManager.fillReport(jasperReport, parameters); The problem is... With that change, i get a blank report, with no info (static or dinamic). Link to comment Share on other sites More sharing options...
lucianc Posted May 5, 2010 Share Posted May 5, 2010 JRXmlUtils.parse(String) takes a string URI as argument.If you want to parse an XML string, do JRXmlUtils.parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8"))) Link to comment Share on other sites More sharing options...
bernardopina Posted May 5, 2010 Author Share Posted May 5, 2010 About 5 minutes ago i solved the puzzle...The problem was that when i did not receive the xpath as a parameter on the servlet, there were no report path seted on the DataSource. All i did was to get the report path from the .jrxml with the line above and set it on the DataSource.The code became this, and now it works perfectly.Thanks A LOT for all the help. =)Code: InputStream inRegistry = (InputStream) new ByteArrayInputStream(xmlRegistry.getBytes()); JasperDesign jasperDesign = JRXmlLoader.load(template); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JRXmlDataSource ds = null; if(xPath != null && !xPath.equals("")) { ds = new JRXmlDataSource(inRegistry,xPath); } else { ds = new JRXmlDataSource(inRegistry,jasperReport.getQuery().getText()); } JasperPrint print = JasperFillManager.fillReport(jasperReport, null, ds); return print; 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