PDA

View Full Version : couldn't get multi report working...



egavaldo
06-15-2005, 12:10 PM
Hi there,
I couldn(t get multi report working here... It's thought very similar to the multireport demo. the exception I'm getting is:


org.jfree.xml.ElementDefinitionException: Failure while including external report definition. [Location: Line=-1 Column=-1]

during parsing...

my joinign report is like this:


...
<groups>
<group name="A Group" >
<fields>

<field>TablePrefix</field>
<field>Employee.EmployeeID</field>
<field>Company.CompanyID</field>
</fields>
</group>
</groups>


<parser-config>
<property name="GroupBackground">#fffb98</property>
</parser-config>
<include src="C&#58;\\PROGRAMMES_ESSAIS\\jdbc2\\src\\report1.xml"/>


<parser-config>
<property name="GroupBackground">#eefbbb</property>
</parser-config>
<include src="C&#58;\\PROGRAMMES_ESSAIS\\jdbc2\\src\\report2.xml"/>
...

and my 2 external reports like this:




<groups>
<group name="A Group" >

<groupheader>
<band name="Employee" fsbold="true" fontsize="12" layout-cachable="false" fontname="SansSerif">
<rectangle x="0" y="0" width="100%" height="100%" color="$&#123;GroupBackground&#125;" fill="true" draw="false"/>
<label x="0" y="0" width="200" height="15">Company</label>
<string-field x="200" y="0" width="200" height="15" fieldname="Employee.CompanyID"/>
<line x1="0" y1="15" x2="100%" y2="15" color="black" width="1" />
</band>
</groupheader>

<groupfooter>
<band name="Employee" fsbold="true" fontsize="12" layout-cachable="false" fontname="SansSerif">
<rectangle x="0" y="0" width="100%" height="100%" color="$&#123;GroupBackground&#125;" fill="true" draw="false"/>
<line x1="0" y1="0" x2="100%" y2="0" color="black" width="1" />
<label x="0" y="3" width="200" height="15">Number of Employees</label>
<number-field x="200" y="3" width="200" height="15" fieldname="CountEmployees"/>
</band>
</groupfooter>

</group>
</groups>


<items height="0" fontname="SansSerif" fontstyle="plain" fontsize="9">
<band name="Employee" fsbold="false" fontsize="10" layout-cachable="false" fontname="SansSerif">
<rectangle x="0" y="2" width="100%" height="10" color="#f1f8f1" weight="0" draw="true" fill="true"/>
<string-field x="0" y="2" width="33%" height="10" alignment="left" fieldname="Employee.CompanyID"/>
<string-field x="33%" y="2" width="33%" height="10" alignment="left" fieldname="Employee.EmployeeID"/>
<string-field x="66%" y="2" width="33%" height="10" alignment="center" fieldname="Employee.EmployeeName"/>
</band>
</items>



<functions>
<function class="org.jfree.report.function.ItemCountFunction" name="CountEmployees">
<properties>
<property name="group">A Group</property>
</properties>
</function>

<function class="org.jfree.report.function.HideElementByNameFunction" name="hideEmployees">
<properties>
<property name="element">Employee</property>
<property name="field">TablePrefix</property>
</properties>
</function>
</functions>

Any ideas ???
Anyway, thanks for this great reporting tool ! I experimented a bit JasperReport and the xml syntax is awful ! Good job guys !
Eg\\*

PS: by the way I'm getting my datas from sql... maybe of interest to add an exemple in the demo ? here is a sniplet...


// **************** DATA1 ********************
private TableModel createData1&#40;&#41; &#123;
Object&#91;&#93; columnNames;
DefaultTableModel result = null;

Statement statement = null;
ResultSet resultSet = null;
try &#123;
statement = connection.createStatement&#40;&#41;;
resultSet = statement.executeQuery&#40;"SELECT * FROM table_employee ORDER BY employee_name"&#41;;

int size=0;
while&#40;resultSet.next&#40;&#41;&#41;
size++;

columnNames = new String&#91;&#93;&#123;"EmployeeID", "CompanyID", "EmployeeName"&#125;;
result = new DefaultTableModel&#40;columnNames, size&#41;;

int i = 0;
resultSet.beforeFirst&#40;&#41;;
while &#40;resultSet.next&#40;&#41;&#41; &#123;
result.setValueAt&#40;resultSet.getString&#40;1&#41;, i, 0&#41;;
result.setValueAt&#40;resultSet.getString&#40;2&#41;, i, 1&#41;;
result.setValueAt&#40;resultSet.getString&#40;3&#41;, i, 2&#41;;
i++;
&#125;

if &#40;resultSet != null&#41;
try &#123;
resultSet.close&#40;&#41;;
&#125; catch &#40;SQLException e&#41; &#123;
System.out.println&#40;"Exception1 " + e&#41;;
&#125;

if &#40;statement != null&#41;
try &#123;
statement.close&#40;&#41;;
&#125; catch &#40;SQLException e&#41; &#123;
System.out.println&#40;"Exception2 " + e&#41;;
&#125;
&#125; catch &#40;Exception e&#41; &#123;
System.out.println&#40;"Exception3 " + e&#41;;
&#125;

return result;
&#125;

Taqua
06-15-2005, 06:33 PM
Hi,

the include tag needs an URL - not an absolute file name. That means: Use "file://c:/yourdir/yourfile.xml" or (the better alternative) a relative pathname relative to the current XML file.

Have mo' fun,
said Thomas

egavaldo
06-16-2005, 04:45 AM
Thank you Taqua,
Yes I first tried this... but:
1) if I use
<include src="file&#58;//c&#58;/PROGRAMMES_ESSAIS/jdbc2/src/report1.xml"/> I get the same exception

2) if I just use
<include src="report1.xml"/> I get
org.jfree.xml.ElementDefinitionException&#58; No route to host&#58; connect &#91;Location&#58; Line=-1 Column=-1&#93; &#91;Location&#58; Line=-1 Column=-1&#93; &#91;Location&#58; Line=-1 Column=-1&#93;

what does it mean ??? is there a way to activate debugging trace during parsing to get a clue on what's wrong ?

Eg\\*

egavaldo
06-20-2005, 08:11 AM
has someone an idea on what could provoke a
org.jfree.xml.ElementDefinitionException&#58; No route to host&#58; connect ? I am sticked on this problem... :(

egavaldo
06-20-2005, 12:05 PM
Hum... some news: I got xml reports from the demo/multireport folder in the jfreereport package and replaced mine by these ones and took the same data that the demo is using and... surprise !!! same error: org.jfree.xml.ElementDefinitionException: No route to host: connect [Location: Line=-1 Column=-1] [Location: Line=-1 Column=-1] [Location: Line=-1 Column=-1] .

What Am I doing wrong ?



package com.toto.database;

import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jfree.report.JFreeReport;
import org.jfree.report.JFreeReportBoot;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.modules.gui.base.PreviewDialog;
import org.jfree.report.modules.parser.base.ReportGenerator;
import org.jfree.report.modules.misc.tablemodel.JoiningTableModel;
import javax.swing.*;

public class CMain &#123;

private TableModel data;
private JFreeReport report;
private Connection connection;

public CMain&#40;&#41; &#123;
data = this.createJoinedTableModel&#40;&#41;;

// display the datas for debug purposes...
JFrame frame = new JFrame&#40;"Table Data Model"&#41;;
frame.setDefaultCloseOperation&#40;JFrame.EXIT_ON_CLOSE&#41;;
JTable table = new JTable&#40;data&#41;;
frame.getContentPane&#40;&#41;.add&#40;table&#41;;
frame.pack&#40;&#41;;
frame.setVisible&#40;true&#41;;


// get the report
report = createReportDefinition&#40;&#41;;

// fill the report
report.setData&#40;data&#41;;

try &#123;
final PreviewDialog preview = new PreviewDialog&#40;report&#41;;
preview.pack&#40;&#41;;
preview.setVisible&#40;true&#41;;
&#125; catch &#40;ReportProcessingException e&#41; &#123;
System.out.println&#40;"Failed to generate report " + e&#41;;
System.exit&#40;0&#41;;
&#125; catch &#40;Exception e&#41; &#123;
System.out.println&#40;"Exception " + e&#41;;
System.exit&#40;0&#41;;
&#125;
&#125;


private TableModel createFruitTableModel &#40;&#41;
&#123;
final String&#91;&#93; names = new String&#91;&#93;&#123;"Id Number", "Cat", "Fruit"&#125;;
final Object&#91;&#93;&#91;&#93; data = new Object&#91;&#93;&#91;&#93;&#123;
&#123; "I1", "A", "Apple"&#125;,
&#123; "I2", "A", "Orange"&#125;,
&#123; "I3", "B", "Water melon"&#125;,
&#123; "I4", "B", "Strawberry"&#125;,
&#125;;
return new DefaultTableModel&#40;data, names&#41;;
&#125;

private TableModel createColorTableModel &#40;&#41;
&#123;
final String&#91;&#93; names = new String&#91;&#93;&#123;"Number", "Group", "Color"&#125;;
final Object&#91;&#93;&#91;&#93; data = new Object&#91;&#93;&#91;&#93;&#123;
&#123; new Integer&#40;1&#41;, "X", "Red"&#125;,
&#123; new Integer&#40;2&#41;, "X", "Green"&#125;,
&#123; new Integer&#40;3&#41;, "Y", "Yellow"&#125;,
&#123; new Integer&#40;4&#41;, "Y", "Blue"&#125;,
&#123; new Integer&#40;5&#41;, "Z", "Orange"&#125;,
&#123; new Integer&#40;6&#41;, "Z", "White"&#125;,
&#125;;
return new DefaultTableModel&#40;data, names&#41;;
&#125;

private TableModel createJoinedTableModel &#40;&#41;
&#123;
final JoiningTableModel jtm = new JoiningTableModel&#40;&#41;;
jtm.addTableModel&#40;"Color", createColorTableModel&#40;&#41;&#41;;
jtm.addTableModel&#40;"Fruit", createFruitTableModel&#40;&#41;&#41;;
return jtm;
&#125;




// **************** REPORT ********************

private JFreeReport createReportDefinition&#40;&#41; &#123;
JFreeReport report = null;
try &#123;
ReportGenerator generator = ReportGenerator.getInstance&#40;&#41;;
report = generator.parseReport&#40;"joined-report.xml"&#41;;
&#125; catch &#40;Exception ex&#41; &#123;
System.out.println&#40;"******** report.definitionfailure ********* " + ex &#41;;
&#125;
return report;
&#125;



public static void main&#40;String&#91;&#93; args&#41; &#123;
JFreeReportBoot.getInstance&#40;&#41;.start&#40;&#41;;
new CMain&#40;&#41;;
&#125;
&#125;

This provokes the following output:


INFO&#58; System.out log target started ... previous log messages could have been ignored.
DEBUG&#58; Init&#58; org.jfree.base.log.DefaultLogModule &#91;logging&#93;
INFO&#58; System.out log target started ... previous log messages could have been ignored.
INFO&#58; Pixie library found. WMF file support will be available.
INFO&#58; Registering fonts for the iText library; using a cached font registry.
INFO&#58; Completed font registration.
INFO&#58; Insufficient Data to create a pageformat&#58; Returned default.
******** report.definitionfailure ********* org.jfree.xml.ElementDefinitionException&#58; No route to host&#58; connect &#91;Location&#58; Line=-1 Column=-1&#93; &#91;Location&#58; Line=-1 Column=-1&#93; &#91;Location&#58; Line=-1 Column=-1&#93;

Any ideas guys ? I'm really lost now...
Eg\\*

egavaldo
06-20-2005, 12:15 PM
FOUND A WORKAROUND !!!!!

It sounds like referencing the dtd in the sub-reports does not work very well ! I downloaded the dtd, copied it locally, referenced this dtd in all the xml directly and it works !


<!DOCTYPE report PUBLIC "-//JFreeReport//DTD report definition//EN//simple/version 0.8.5"
"report-085.dtd">

Sounds like a bug doesn't it ?
Eg\\*

Mimil
06-20-2005, 01:27 PM
Hi,

Yes, it seems. I guess it is same problem as in http://www.jfree.org/phpBB2/viewtopic.php?t=13117 topic.
So it should be solved in the CVS for now.

Anonymous
06-21-2005, 03:27 AM
Hum... not sure it's the same problem since I am connected to the internet...
Eg\\*

Taqua
06-21-2005, 09:01 AM
Hi,

the mentioned fix has been released as version 0.8.5-5 on June 1st.

Your way to create a result set will give you trouble, if you want to compute sums, format the number or do something else than just printing strings.

Either use resultSet.getObject(..) or feed the result set into the ResultSetTableModelFactory supplied with JFreeReport.

Have mo' fun,
said Thomas