[#807] - Pass the current JasperReports if exists for JRDSProvider

Category:
Feature request
Priority:
Low
Status:
Assigned
Project: Severity:
Trivial
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:

Issue moved from:
https://sourceforge.net/tracker/index.php?func=detail&aid=1314863&group_...

Consult the original issue for any attachments.

[ 1314863 ] Pass the current JasperReports if exists for JRDSProvider

Submitted By: Stephen Lawlor - slawlor
Date Submitted: 2005-10-06 05:15
Last Updated By: gt78 - Comment added
Date Last Updated: 2006-03-06 09:36
Number of Comments: 6
Number of Attachments: 0

Assigned To: Giulio Toffoli
Priority: 5

Summary:
Pass the current JasperReports if exists for JRDSProvider

iReport menu option: Datasource/Report Query Tab: "Use datasource provider" Button: "Get fields from datasource" Problem: Fails if you read the JasperReports parameter
in the JRDataSourceProvider because the parameter is null.
.
The JasperReport parameter is always set to null. I have updated this as follows, however, I think this fix is fragile - it's dependant on a previous compile and
the location of the compiled file. I would recommend that the parameter for getFields be "JRVariables[]" which I think might be available without a compile.

Steve.

private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_jButton2ActionPerformed

IReportConnection conn =
(IReportConnection)this.getJReportFrame().getMainFrame().getProperties().get("DefaultConnection");
if (conn == null || !(conn instanceof
it.businesslogic.ireport.connection.JRDataSourceProviderConnection))
{
setColumnsError( "The active connection is
not a JasperReports DataSource provider." );
return;
}
else
{

it.businesslogic.ireport.connection.JRDataSourceProviderConnection
ic =
(it.businesslogic.ireport.connection.JRDataSourceProviderConnection)conn;
try {
// SL-01:6-Oct-2005:Start
String fileName =
this.getJReportFrame().getReport().getFilename();
fileName =
Misc.changeFileExtension(fileName,"jasper");
JasperReport jasper_report_obj =
JasperManager.loadReport(fileName);
net.sf.jasperreports.engine.JRField[]
jrfields = ic.getDataSourceProvider().getFields(
jasper_report_obj );
// net.sf.jasperreports.engine.JRField[]
jrfields = ic.getDataSourceProvider().getFields( null );
// SL-01:6-Oct-2005:End
DefaultTableModel dtm =
(DefaultTableModel)jTableFields.getModel();
dtm.setRowCount(0);
for (int i=0; i< jrfields.length; ++i)
{
it.businesslogic.ireport.JRField field
= new
it.businesslogic.ireport.JRField(jrfields[i].getName(),
jrfields[i].getValueClassName());
field.setDescription(
it.businesslogic.ireport.util.Misc.nvl(
jrfields[i].getDescription(),""));
Vector row = new Vector();
row.addElement(field);
row.addElement(field.getClassType());
row.addElement(field.getDescription());
dtm.addRow(row);
}
} catch (Exception ex)
{
setColumnsError( "" + ex.getMessage() );

}
}

}//GEN-LAST:event_jButton2ActionPerformed

Comments

Date: 2006-03-06 09:36
Sender: gt78SourceForge.net SubscriberProject Admin
Logged In: YES
user_id=616744

I will evaluate the possibility to pass a temporary
JasperReport object containing only properties and parameters

Giulio

Date: 2006-03-06 03:18
Sender: slawlor
Logged In: YES
user_id=994679

Giulio,
getFields(report) *may* take null but without my fix the "report" parameter will never be anything but null because of
"net.sf.jasperreports.engine.JRField[] jrfields =
ic.getDataSourceProvider().getFields( null );"

This causes a problem for me because I use a variable in the report to specify log-in and related information which my DataSourceProvider requires before it can return a list of fields (or do anything else). So I must be able to pass in the report.
My fix works for me but as I say I don't think it's a great solution. I suspect the main reason for passing in the report is to supply report variable and/or parameter
information to the "GetFields" process. I think it would be better to be able to pass this information directly without requiring the presence of a compiled report (however I admit I don't know enough to know whether this is feasible). Either way the call to getFields should not assume that the parameter report will always be null.

Thanks,
Steve

Date: 2005-10-26 05:09
Sender: gt78SourceForge.net SubscriberProject Admin
Logged In: YES
user_id=616744

In the Query window, a JRDataSourceProvider is used to get
fields that will be used in this report:

* Returns the fields that are available from the data source.
* The provider can use the passed in report to extract some additional
* configuration information such as report properties.
*
* @param report the report that will be filled using the data source created by this provider.
* The passed in report can be null. That means that no compiled report is available yet.
* @return a non null fields array. If there are no fields then an empty array must be returned.
*
* @throws UnsupportedOperationException is the method is
not supported
* @throws JRException if an error occurs.
*/
public JRField[] getFields(JasperReport report) throws JRException, UnsupportedOperationException;

As you can see, fields are not taken by the report passed in. A null value passed in is typical.

Let me know what you think about and what exactly your code
fixs.

Please note:you use a DataSourceProvider to get fields for this report instead of getting fields from an SQL query. When the report is executed, the datasource provider (if it's the active datasource) will be used to obtain a JRDataSource.

Giulio

Giulio

Date: 2005-10-26 04:37
Sender: gt78SourceForge.net SubscriberProject Admin
Logged In: YES
user_id=616744

Sorry Steve,

I was responding to another bug :-) Ok, now I'm dealing with your one.

Giulio

Date: 2005-10-26 04:15
Sender: slawlor
Logged In: YES
user_id=994679

Thanks for the response Giulio however I think there must be some misunderstanding. The code was:
"net.sf.jasperreports.engine.JRField[] jrfields =
ic.getDataSourceProvider().getFields( null );"

which will never return the list of fields because the compiled report is not available to the getFields(compiled report) method.

Steve.

Date: 2005-10-26 03:51
Sender: gt78SourceForge.net SubscriberProject Admin
Logged In: YES
user_id=616744

You can try

ireport -h

to see some command line options about paths.

giulio

No Files Currently Attached

tcloonan's picture
1667
Joined: Dec 22 2006 - 1:13am
Last seen: 15 years 7 months ago
Feedback
randomness