By: Thomas Richter - hornet_f4c
Simple JRTableDataSource Example...
2002-11-06 11:07
Hi there,
I just played around with Jasperreports and it seems to be very promising. The data I am ging to report is already provided as swing TableModel, so the usage of the JRTableModel DataSource should be the way to go.
I went through the DataSourceReports example and everything worked fine so far.... but :
The DataSourceReport.xml defines specific field ids. So when using another table as input, it will not work, because the defined fields cannot be found.
Now, the fieldIDs in my table are years (eg.2000,2001,2002...). Those may change from time to time. So what I want to do at the first step is to simply display my table as it is.
Is there a way to simply display a table without having to define specific field names in the xml before ?
I mean, JR should be able retrieve the columnCount and the coulmnNames from the TableModel and then just display the table as it is.
How to do this ?
Thanks in advance
By: Teodor Danciu - teodord
RE: Simple JRTableDataSource Example...
2002-11-06 13:17
Hi,
Do you know that the JRTableModelDataSource
lets you name your fields using the index of the
column in the TableModel?
Fields can be named: COLUMN_1 for the first
column, COLUMN_2 for the second and so on.
I'm not sure this is what you need, but if not,
I'm afraid you are talking about dinamic report
designs and you should check the "noxmldesign"
sample to see how to create report designs on the
fly using the JasperReports API.
Thank you,
Teodor
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-07 06:24
Oh thanx . Yes that helps :) Just found it our myself before reading your answer !
Still I have a follow up question. In the XML design I specify the type of the column. E.g. "java.lang.String" ... now my Table consists of an Object called "Value" - an own implementation.
How can I tell JasperReports how to evaluate own Objects ?? (eg. for Values it would have to call getString() to get a String representation)
Thanks for your support !
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-07 08:38
Ok, in the meantime I found out that in the xml:
...I cannot define the FieldTypes directly using a custom class, but instead:
1. I can define my FieldTypes as java.lang.Object and
2. Then inside the TextFieldExpression I can cast to my custom class and call Methods from the Objects.
So my Field Definitions look like this:
<field name="COLUMN_0" class="java.lang.Object"/>
and my TextFieldExpressions look like this:
<textFieldExpression class="java.lang.String">
""+String.valueOf(((com.top_logic.base.reporting.data.base.value.Value)$F{COLUMN_0}).getAllEntriesAsString())
</textFieldExpression>
...where the String.valueOf - call is actually useless since the getAllEntriesAsString already returns a String.
The class Value I use here is an interface implemented by the Objects hold by my table.
The xml compiles without problems. But when running the template (which I do in the application context of the webapplication) I get a ClassnotfoundException because the Interface value cannot be found. But since this interface is already used within the webapp, I have no idea where to update which classpath, so that this class is found by the JasperRunManager....
Probably hard to answer without knowing the environment, but maybe I missed something general.
To make it short. Compiling is done with the environment of the examples which came with JR. Own environment. The Interface Value is added manually to the classpath, so the xml will compile.
Then when trying to run the Jasperfile, this is done in the Webapplication with the JR jars manually added to the Webapps classpath. Here JR throws an exception because it cannot find the interface Value.
Thanks - hope this was not too confusing.
Cya
By: Teodor Danciu - teodord
RE: Simple JRTableDataSource Example...
2002-11-07 13:38
Hi,
The jasperreports.jar file should be placed in the
same classpath location as the application classes.
If that particular interface of yours in in the
WEB-IN/classes directory of your web application,
then the jasperreports.jar should be placed in the
WEB-INF/lib directory of that Web application.
Make sure you don't have a copy of the JAR file
in other classpath location and that the server does
not load that first.
I hope this helps.
Teodor
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-08 17:53
Yeah - thanx. That did the trick....
Hell I feel silly now. I really had the jar file in the common/lib of tomcat instead of the web-inf/lib. Sorry for bothering you with that kind of stuff. And thanx a lot for your patience :)
Cya
Simple JRTableDataSource Example...
2002-11-06 11:07
Hi there,
I just played around with Jasperreports and it seems to be very promising. The data I am ging to report is already provided as swing TableModel, so the usage of the JRTableModel DataSource should be the way to go.
I went through the DataSourceReports example and everything worked fine so far.... but :
The DataSourceReport.xml defines specific field ids. So when using another table as input, it will not work, because the defined fields cannot be found.
Now, the fieldIDs in my table are years (eg.2000,2001,2002...). Those may change from time to time. So what I want to do at the first step is to simply display my table as it is.
Is there a way to simply display a table without having to define specific field names in the xml before ?
I mean, JR should be able retrieve the columnCount and the coulmnNames from the TableModel and then just display the table as it is.
How to do this ?
Thanks in advance
By: Teodor Danciu - teodord
RE: Simple JRTableDataSource Example...
2002-11-06 13:17
Hi,
Do you know that the JRTableModelDataSource
lets you name your fields using the index of the
column in the TableModel?
Fields can be named: COLUMN_1 for the first
column, COLUMN_2 for the second and so on.
I'm not sure this is what you need, but if not,
I'm afraid you are talking about dinamic report
designs and you should check the "noxmldesign"
sample to see how to create report designs on the
fly using the JasperReports API.
Thank you,
Teodor
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-07 06:24
Oh thanx . Yes that helps :) Just found it our myself before reading your answer !
Still I have a follow up question. In the XML design I specify the type of the column. E.g. "java.lang.String" ... now my Table consists of an Object called "Value" - an own implementation.
How can I tell JasperReports how to evaluate own Objects ?? (eg. for Values it would have to call getString() to get a String representation)
Thanks for your support !
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-07 08:38
Ok, in the meantime I found out that in the xml:
...I cannot define the FieldTypes directly using a custom class, but instead:
1. I can define my FieldTypes as java.lang.Object and
2. Then inside the TextFieldExpression I can cast to my custom class and call Methods from the Objects.
So my Field Definitions look like this:
<field name="COLUMN_0" class="java.lang.Object"/>
and my TextFieldExpressions look like this:
<textFieldExpression class="java.lang.String">
""+String.valueOf(((com.top_logic.base.reporting.data.base.value.Value)$F{COLUMN_0}).getAllEntriesAsString())
</textFieldExpression>
...where the String.valueOf - call is actually useless since the getAllEntriesAsString already returns a String.
The class Value I use here is an interface implemented by the Objects hold by my table.
The xml compiles without problems. But when running the template (which I do in the application context of the webapplication) I get a ClassnotfoundException because the Interface value cannot be found. But since this interface is already used within the webapp, I have no idea where to update which classpath, so that this class is found by the JasperRunManager....
Probably hard to answer without knowing the environment, but maybe I missed something general.
To make it short. Compiling is done with the environment of the examples which came with JR. Own environment. The Interface Value is added manually to the classpath, so the xml will compile.
Then when trying to run the Jasperfile, this is done in the Webapplication with the JR jars manually added to the Webapps classpath. Here JR throws an exception because it cannot find the interface Value.
Thanks - hope this was not too confusing.
Cya
By: Teodor Danciu - teodord
RE: Simple JRTableDataSource Example...
2002-11-07 13:38
Hi,
The jasperreports.jar file should be placed in the
same classpath location as the application classes.
If that particular interface of yours in in the
WEB-IN/classes directory of your web application,
then the jasperreports.jar should be placed in the
WEB-INF/lib directory of that Web application.
Make sure you don't have a copy of the JAR file
in other classpath location and that the server does
not load that first.
I hope this helps.
Teodor
By: Thomas Richter - hornet_f4c
RE: Simple JRTableDataSource Example...
2002-11-08 17:53
Yeah - thanx. That did the trick....
Hell I feel silly now. I really had the jar file in the common/lib of tomcat instead of the web-inf/lib. Sorry for bothering you with that kind of stuff. And thanx a lot for your patience :)
Cya
0 Answers:
No answers yet