PDA

View Full Version : No data in the preview frame



Anonymous
09-03-2002, 08:55 AM
Hi

I downloaded the JFreeReport and able to run the demo successfully. I also purchased the documentation so that I thought I can utilize it more in my projects. Here is the problem I am facing right now. The sample code below:

public class ReportDAO extends AbstractDataModel{

// get connection

// get data (Select empId,ename, salary,hiredate from emp where
hiredate between 'fromdate' and 'todate'
)

// put the data in a Vector of Vectors.

// Able to print the data using System.out

}

public class ReportViewer {

public void getReport(String urlname, TableModel data){

URL in = new URL(urlname);

System.out.println("the url is "+in);
ReportGenerator gen = ReportGenerator.getInstance ();

JFreeReport report1 = null;
try {
report1 = gen.parseReport (in, in);

}
catch (Exception ioe) {
System.out.println ("report.definitionfailure"+ ioe);

}


report1.setData (data);

PreviewFrame frame1 = new PreviewFrame (report1);
frame1.pack ();
RefineryUtilities.positionFrameRandomly (frame1);
frame1.setVisible (true);
frame1.requestFocus ();
}

public static void main(String[] args){

ReportViewer viewer = new ReportViewer();
ReportDAO report = new ReportDAO();

viewer.getOfferReport ("first.xml",report);
// Reading the xml file properly
}
}

Once I run this class, the preview pane is showing up but without any data.
Only showing the report header. In the getValueAt(int p, int q) function in ReportDAO, the system.out.println is actually printing the values.

My xml file is like this:
<report
report name="First Report" width="468" height="648">


<reportheader height="112" fontname="SansSerif" fontstyle="plain" fontsize="10">

<label name="label1" fontname="SansSerif" fontstyle="bold" fontsize="18" x="0" y="0" width="100%" height="18" alignment="center">
Employees joined between the given dates
</label>

</reportheader>

<reportfooter height="48" fontname="Serif" fontstyle="bold" fontsize="16">

<label name="Label 2" x="0" y="0" width="100%" height="24" alignment="center">*** END OF REPORT ***</label>
</reportfooter>


<pageheader height="18" fontname="Serif" fontstyle="plain" fontsize="10" onfirstpage="true">
<rectangle x="0" y="0" width="100%" height="100%" color="#AFAFAF" weight="0"/>
<date-function name="date1" x="0" y="0" width="100%" height="14" alignment="right" baseline="12" format="d-MMM-yyyy" function="report_date"/>
<line name="line1" x1="0" y1="16" x2="0" y2="16" color="#CFCFCF" weight="2.0"/>
</pageheader>

<pagefooter height="18">

</pagefooter>

<items height="10" fontname="Monospaced" fontstyle="plain" fontsize="8">
<rectangle name="background" x="0" y="0" width="100%" height="100%" color="#DFDFDF" weight="0"/>
<line name="top" x1="0" y1="0" x2="0" y2="0" color="#DFDFDF" weight="0.1"/>
<line name="bottom" x1="0" y1="10" x2="0" y2="10" color="#DFDFDF" weight="0.1"/>
<!-- <number-field name="EmpId Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="EMPID"/>
<number-field name="NameElement" x="260" y="0" width="76" height="8" alignment="right" format="#,##0" fieldname="ENAME"/>
<string-field name="Salary Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="SALARY"/>
<date-field name="HireDate Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="HIREDATE"/>-->

</items>

<functions>

<function name="Date" class="com.jrefinery.report.function.ReportPropertyFunction">
<properties>
<property name="reportProperty">report.date</property>
</properties>
</function>

<function name="PageNumber" class="com.jrefinery.report.function.PageFunction"/>


</functions>
</report>

I am seeing only the Employees joined between the given dates in the report header and ******* End of Report ****** in the footer.

Please help...

Thanks in advance.

Prakash

Anonymous
09-03-2002, 08:58 AM
Actullay there are no comments between the data fields as appeared in my original post: No data in the preview frame

<number-field name="EmpId Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="EMPID"/>
<number-field name="NameElement" x="260" y="0" width="76" height="8" alignment="right" format="#,##0" fieldname="ENAME"/>
<string-field name="Salary Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="SALARY"/>
<date-field name="HireDate Element" x="260" y="0" width="76" height="8" alignment="right" fieldname="HIREDATE"/>

Thanks

prakash

Anonymous
09-03-2002, 12:38 PM
Hi,

first question: Are the top and bottom lines and the background printed? Second: the field names you reference exist in the datamodel, you have changed the getColumnName() function to return the proper names and then names have uppercase as the fieldnames you refer to?

Have more fun,
said Thomas

Anonymous
09-03-2002, 05:59 PM
Hello

Thank you for your speedy reply. I sorted out the problem and now it is printing the data properly and also able to export as pdf.

But now another problem.

Is it possible to target the data as html file instead of pdf so that I can have the grouping, totals etc. Also I am generating the charts(pie, bar, stacked etc) using cewolf taglibs. How to add them in the report generated by JFreeReport.

small example with sample code is very much appreciated or any links so that I can explore.

Thanks in advance

Prakash