Jump to content
Changes to the Jaspersoft community edition download ×

JRSortableDataSource Problem


pinoytechie

Recommended Posts

I'm developing a custom JRDataSourceProvider for Lotus Domino.

 

I have also a custom JRDataSource object for use with Lotus Domino. This custom JRDataSource exposes a member called getProvider(), this is to get the provider which is being created by iReport, since there is no parameter/variable in iReport to get a custom provider.

 

The provider also exposes a Domino Session object for use in the creation of new custom JRDataSource to be used in subreport, i.e. in the Data Source Expression of subreport, I could specify:

myPackage.createCustJRDSource(((myPackage.customJRDSource)$P{REPORT_DATA_SOURCE}).getProvider().getDominoSession(), "MyNotesView");

 

I have to use only one Domino Session for this implementation, otherwise other Domino objects will not be synchronized. This is what Domino documentation emphasized.

 

This works like a charm.

 

The problem is when one or more sort fields are specified in the report, the REPORT_DATA_SOURCE parameter becomes JRSortableDataSource, which throws ClassCastException when I try to run the report. That is because, the subreport expression casts it to customJRDSource, to invoke the getProvider() member.

 

How would I workaround this problem? It's going to be a real pain if I will implement the my own sorting :(

 

Thank you very very much.

Post edited by: pinoytechie, at: 2007/05/10 20:23

Link to comment
Share on other sites

  • Replies 15
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

Here's a fortunate strange trick that you could do:

Capture your original data source using the default value expression of a dummy parameter like this:

 

<parameter name="MyDataSource" class="net.sf.jasperreports.engine.JRDataSource">

<defaultValueExpression>$P{REPORT_DATA_SOURCE}</defaultValueExpression>

</parameter>

 

Use the MyDataSource parameter where you need your original data source instance in expressions.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 3 months later...

I am glad that you published this fix, however why not add another default property for the original datasource similar to the 'REPORT_DATASOURCE'? Another possible fix would be to add a method to the JRSortableDataSource to return the original.

 

Similar to the original post on this thread I have created my own datasource to deal with particular features of my db, however this does not work if I ever want to sort the results on the front end.

Link to comment
Share on other sites

Hi,

 

Why the proposed fix is not enough or not working in your case?

 

Having too many built-in parameters would become confusing at some point and we are trying to avoid it if at all possible. Keeping built-in parameters to a minimum is ideal.

 

Thank you,

Teodor

Link to comment
Share on other sites

I have a similar problem that also generates a ClassCastException.

 

When I try to sort by a field that comes with java (String, int, etc) everything works fine. But if I try to put a custom field so an error occur.

 

What may it be?

Link to comment
Share on other sites

fsaa wrote:

When I try to sort by a field that comes with java (String, int, etc) everything works fine. But if I try to put a custom field so an error occur.

 

If you use a field for sorting, its type/class needs to implement java.util.Comparable so that the engine is able to compare and sort field values.

 

HTH,

Lucian

Link to comment
Share on other sites

lucianc wrote:

fsaa wrote:
When I try to sort by a field that comes with java (String, int, etc) everything works fine. But if I try to put a custom field so an error occur.

 

If you use a field for sorting, its type/class needs to implement java.util.Comparable so that the engine is able to compare and sort field values.

 

HTH,

Lucian

 

Lucianc, thank you. It worked.

 

Well, I still have a problem. When I try to put as sort fields those fields that are retrieved from objects references that are encapsulated in the object references inserted in the JavaBeanCollection, then I get the following error:

 

CausedÂby:Âjava.lang.NoSuchMethodException:ÂUnknownÂproperty

 

Bye.

Link to comment
Share on other sites

fsaa wrote:

Well, I still have a problem. When I try to put as sort fields those fields that are retrieved from objects references that are encapsulated in the object references inserted in the JavaBeanCollection, then I get the following error:

Caused by: java.lang.NoSuchMethodException: Unknown property

 

I think an example (relevant JRXML fragments, etc) would make the issue easier to understand. Please post the full stacktrace as well.

 

Does the report work if you remove the sort fields?

 

Regards,

Lucian

Link to comment
Share on other sites

lucianc wrote:

I think an example (relevant JRXML fragments, etc) would make the issue easier to understand. Please post

the full stacktrace as well.

Does the report work if you remove the sort fields?

Regards,
Lucian

 

Yes, the report runs ok if I remove that field I mentioned. Concerning the example, here we go!

 

 

I am attaching a zip file containing two JRXML files, one that runs (without the sorting field) and another

(with the sorting field) that is getting the error showed in the end of this message.

 

You must know some things about the classes I am working with:

 

1- The javaBeanCollection object that's being given to the report as its DataSource has elements of the type "MovimentacaoProcesso". One field of this class is of the type "Processo". Inside Processo, there is a field of the type ClasseProcessual. Inside ClasseProcessual there is a field of the type String and its name is "Descricao". This latter field is just the field that when used as sorting field, makes the report to get the error we are talking about.

 

2- When I try to use any field of MovimentacaoProcesso class, everything goes allright. So, I conclude that the problem just happens when I use as sorting fields those fields that are not directly in the class which is an element of the DataSource, i.e., fields that are being retrieved through the tree of encapsulation.

 

 

Thank for your help.

Best regards!

fsaa.

 

 

THE ERROR LISTING

-----------------

Error filling print... Error retrieving field value from bean : descricao

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : descricao at

 

net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:116)

 

at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue

 

(JRAbstractBeanDataSource.java:93) at

 

net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue

 

(JRBeanCollectionDataSource.java:104) at net.sf.jasperreports.engine.data.JRSortableDataSource.<init>

 

(JRSortableDataSource.java:123) at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource

 

(JRFillDataset.java:621) at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters

 

(JRBaseFiller.java:892) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:716)

 

at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:688) at

 

net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at

 

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at

 

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517) at

 

it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:968) at java.lang.Thread.run

 

(Thread.java:595) Caused by: java.lang.NoSuchMethodException: Unknown property 'descricao' at

 

org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1122) at

 

org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686) at

 

org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715) at

 

org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290) at

 

net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:104)

 

... 12 more

Print was not filled. Try using an EmptyDataSource... [file name=reports-ff8969cdbe276f15dcedfb4559e794f8.zip size=2991]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/reports-ff8969cdbe276f15dcedfb4559e794f8.zip[/file]

Link to comment
Share on other sites

fsaa wrote:

lucianc wrote:
Does the report work if you remove the sort fields?

 

Yes, the report runs ok if I remove that field I mentioned.

 

I'll rephrase my question: does the report work when you remove the <sortField>s (but keep the <field> which was used in the sort field)?

 

If it doesn't work, then it's a problem with the data source and field mappings, and not with the sort fields.

 

How are you creating the data source? JRBeanCollectionDataSource has a constructor that receives a isUseFieldDescription flag, are you sending that argument to false?

 

Regards,

Lucian

Link to comment
Share on other sites

1. The answer is no. In fact, as you've wondered, it suffices the field (that I want to use as sorting field) be in the list of fields for the report to undergoe the error.

 

2. Even though, I think the reason of the problem is not related to the constructor of dataSource. I say this because my test is being run inside iReport environment, i.e., I am using a connection under iReport environment. The problem happens with/without checking the "use field description" check box within the "connection properties" window.

 

3. I really think the reason is related to the fact that the property I am trying to use in my report is not a field of the class that is being used as the element of the collection (I will reference this class as class-A). The field is from another class (I will call this one as class-C) with which class-A has a indirect relationship, i.e, be using encapsulation concepts. Give a look to the example below:

 

 

class-A (a1<class-B>, ... other fields)

class-B (b1<class-C>, ... other fields)

class-C (c1<String>, ... other fields)

 

 

Note: a1 is of class-B type, b1 is of class-B type

and c1 of String type.

 

 

Class-A is the type of the element in the collection that is being used as datasource. I am trying to use field "c1" as a sort field.

 

I want to stress that if I try to retrieve any field from class-A the report runs without problems. If I try to use any field from other than class-A, the report doesn't run.

 

 

my best

fsaa.

Link to comment
Share on other sites

The JR bean collection/array data sources use Commons BeanUtils to retrieve bean property values, and BeanUtils supports nested bean properties.

 

Looking at your stacktrace

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : descricao

it is clear that the field description (processo.classe.descricao) is not used as field mapping. Maybe the "use field description" flag does not work properly in iReport.

 

Try to change the field name to processo.classe.descricao and see whether the report works.

 

Regards,

Lucian

Link to comment
Share on other sites

Lucian,

 

one more thing. I realized that I gave you a wrong information. I tried again to run the report with checking the field "use field description" box and keeping the field just as "descricao" and I got surprised because it simply worked! I really thought that I had already tried and got error when running with/without checking the aforementioned field, but, as I can see, I missed something.

 

Regards

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...