Jump to content
JasperReports Library 7.0 is now available ×

Custom Datatype in crosstab


mzellers

Recommended Posts

I'm trying to make a crosstab report. In order to get the rows and columns ordered correctly, I need to define my own datatype so I can implement compareTo() and toString().

 

When I tried to do this, I got the following error:

 

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:

 

Code:
C:EclipseeclipseUntitled_report_1_1174700606968_425321.java:167: inconvertible types found : com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase required: java.lang.String value = (java.lang.String)(((com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase)field_PLANNAME.getValue())); ^ 

 

with the subsequent explanation:

 

Code:
[code]C:EclipseeclipseUntitled_report_1_1174700606968_425321.java:167: inconvertible types
found : com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase
required: java.lang.String
value = (java.lang.String)(((com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase)field_PLANNAME.getValue()));

 

Does my custom datatype need to implement a specific interface? I expected that Jasper would use my classes toString() method to render it, but that appears not to be the case.

 

 

I tried adding a getValue() method to my class, but that did not help matters.

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Lucian,

 

Here's my jrxml file. What I'm trying to achieve is to generate a crosstab report where the order of the rows and columns is not the order of the labels. I can't be the first person to try to do this.

 

I thought the way to go was to define my own java class and return values of that class, but apparently not.

 

So how do you create such a crosstab report?

 

Mark Z.

Link to comment
Share on other sites

Your approach is correct (but make sure you implement equals() and hashCode() as well for your type).

 

The errors are caused by inconsistent types across report fields and crosstab groups:

Code:

<field name="ACCOUNTNAME" class="com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase"/>
...
<rowGroup name="ACCOUNTNAME" width="100">
<bucket>
<bucketExpression class="java.lang.String"><![CDATA[$F{ACCOUNTNAME}]]></bucketExpression>

 

$F{ACCOUNTNAME} is a APJasperAxisEntityBase, hence the ACCOUNTNAME row group bucket should have the same type. Note that then you'd have to manually do toString() in the text fields:

Code:
[code]
<rowGroup name="ACCOUNTNAME" width="100">
<bucket>
<bucketExpression class="com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase"><![CDATA[$F{ACCOUNTNAME}]]></bucketExpression>
...
<textFieldExpression class="java.lang.String"><![CDATA[$V{ACCOUNTNAME}.toString()]]></textFieldExpression>

 

HTH,

Lucian

Link to comment
Share on other sites

Lucien,

 

Just as you were posting your response, I noticed that I needed to change the textFieldExpressiontypes in the jrxml from string to my custom type (not just the buckets). Then I saw your response and added the equals() and hashCode() methods to my type.

 

Now I get the error:

 

net.sf.jasperreports.engine.JRException: Report design not valid : 1. No comparator expression specified and the value class is not comparable for crosstab group PLANNAME. 2. No comparator expression specified and the value class is not comparable for crosstab group ACCOUNTNAME.

 

Both PLANNAME and ACCOUNTNAME are of my custom type.

 

I expected that it would use the compareTo() method of my class, but apparently I need to implement an explicit comparator class to compare to objects of my type. Where do I hook that up, in the jrxml or do I need to connect it somehow in the java?

 

Thanks,

 

Mark Z.

Link to comment
Share on other sites

I made some further progress, but I'm not quite there yet.

 

I defined my buckets as:

 

Code:
						<bucket>
<bucketExpression class="com.adaptiveplanning.ui.page.reports.APJasperAxisEntityBase"><![CDATA[$F{PLANNAME}]]></bucketExpression>
<comparatorExpression><![CDATA[$F{PLANNAME}]]></comparatorExpression>
</bucket>

 

And in the definition of my custom class I defined it as implementing the java.lang.Comparator interface. My class defines compare(Object o1, Object o2), equals and hashCode.

 

When I try to run the report, I get the error:

Code:
[code]The bucket expression values are not comparable and no comparator specified.

 

Tracing into the function that threw the error, I see that it is trying to get the id of my object and cast that to a comparator, when then comes back as null.

 

What should I be using for my comparatorExpression?

 

Thanks,

 

Mark Z.

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