mzellers Posted March 24, 2007 Share Posted March 24, 2007 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 More sharing options...
lucianc Posted March 26, 2007 Share Posted March 26, 2007 You are using the group variable in a context where a String value is expected. Can't say more without seeing the JRXML. Regards,Lucian Link to comment Share on other sites More sharing options...
mzellers Posted March 26, 2007 Author Share Posted March 26, 2007 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 More sharing options...
mzellers Posted March 26, 2007 Author Share Posted March 26, 2007 Ooops...I tried to attach the JRXML file as an image. Once more with feeling. [file name=hand_edited_crosstab.jrxml size=12826]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/hand_edited_crosstab.jrxml[/file] Link to comment Share on other sites More sharing options...
lucianc Posted March 27, 2007 Share Posted March 27, 2007 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 More sharing options...
mzellers Posted March 27, 2007 Author Share Posted March 27, 2007 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 More sharing options...
mzellers Posted March 27, 2007 Author Share Posted March 27, 2007 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 More sharing options...
lucianc Posted March 27, 2007 Share Posted March 27, 2007 Your APJasperAxisEntityBase class should implement java.lang.Comparable and not java.util.Comparator. The Comparable interface contains the int compareTo(Object o) method. HTH,Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now