Jump to content
We've recently updated our Privacy Statement, available here ×

Report with XPath configured not working. Help!?


bernardopina

Recommended Posts

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

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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,

Lucian

Code:
parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, JRXmlUtils.parse(xmlFile));JasperPrint print = JasperFillManager.fillReport(report, parameters);
Link to comment
Share on other sites

 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

 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...