Re: JasperReport LocalDate question
Re: JasperReport LocalDate question
- Subject: Re: JasperReport LocalDate question
- From: Kieran Kelleher <email@hidden>
- Date: Tue, 1 Feb 2011 10:56:35 -0500
Theodore,
I am sure that somewhere in your template you have defined either a (1) Field Class, or (2) an Expression class as a Date, or possibly (3) you are using a joda LocalDate in an expression function that takes a param of a Date. This is not a bug. You are doing something wrong.
Your error messages are giving you a clue:
value = (java.util.Date)(((org.joda.time.LocalDate)field_invoiceDateTimestamp.getValue()));
that expression simply will not work. LocalDate cannot be cast to a Date.
I have not worked with Jasper for a few months, so details might be a little fuzzy, but if for example you want a group by, or order by expression derived from a LocalDate, then you can convert it to a simple String, Long or Integer and group/order on that result...... for example, assuming "field_invoiceDateTimestamp" is a joda LocalDate......
[Long] value = Long.valueOf( field_invoiceDateTimestamp.getLocalMillis() );
OR
[String] value = field_invoiceDateTimestamp.toString();
Not sure what you are trying to do with it. In any case, you need to work directly with LocalDate class and its methods and forget about java.util.Date since Joda LocalTime is not a Date and cannot be cast to a Date since it does not subclass Date.
-Kieran
On Feb 1, 2011, at 9:38 AM, Theodore Petrosky wrote:
> From your example video at the places you noted, I added the joda-time-1.6.2.jar to the same folder as iReport and added the Class Path.
>
> I used the org.joda.time.LocalDate for the Field Class Definition. I still get the compile time error that it can not cast from LocalDate to java.util.Date:
>
> So I tried changing to an NSTimestamp to see if I installed the jars correctly and Voila. No compilation errors. So it looks like Joda LocalDate does not Extend java.util.Date.
>
> We have entered the world of, "I have no idea where to go now".
>
> Thanks for your help.
>
> Ted
>
> Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@d8a9586 net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. Cannot cast from LocalDate to Date value = (java.util.Date)(((org.joda.time.LocalDate)field_invoiceDateTimestamp.getValue())); //$JR_EXPR_ID=12$ <--------------------------------------------------------------------------------> 2. Cannot cast from LocalDate to Date value = (java.util.Date)(((org.joda.time.LocalDate)field_invoiceDateTimestamp.getOldValue())); //$JR_EXPR_ID=12$ <-----------------------------------------------------------------------------------> 3. Cannot cast from LocalDate to Date
> value = (java.util.Date)(((org.joda.time.LocalDate)field_invoiceDateTimestamp.getValue())); //$JR_EXPR_ID=12$ <--------------------------------------------------------------------------------> 3 errors at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:191) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:498) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
>
> --- On Mon, 1/31/11, Kieran Kelleher <email@hidden> wrote:
>
>> From: Kieran Kelleher <email@hidden>
>> Subject: Re: JasperReport LocalDate question
>> To: "Theodore Petrosky" <email@hidden>
>> Cc: "Paul Hoadley" <email@hidden>, "WebObjects-Dev Mailing List List" <email@hidden>
>> Date: Monday, January 31, 2011, 8:13 AM
>> JR is looking for a java.util.Date
>> because in the iReport template you have defined a field as
>> a java.util.Date.
>>
>> First, sorry, but the API compatible example is not yet
>> committed to Wonder. Long story short, I have been too busy
>> with my work, but it is still on my TO DO list and I
>> am feeling anxious (aka., motivated) to get it done as soon
>> as I get a chance which may be sooner rather than later.
>> Meanwhile the original pre-Wonder framework and working
>> example are still available in the http://montreal2010.googlecode.com/svn/trunk/ SVN
>> repository and can be checked out into a separate workspace
>> for playing with and learning.
>>
>>
>> OK, now back to your problem. Your problem is easily
>> solvable by using the Joda class for your field definition
>> inside your iReport template.
>>
>> To find out how, just go to the JasperReports video at
>> about 39 minutes in and listen to the discussion about
>> NSTimestamp, which iReport knows nothing about either. In
>> the video, it shows you how to add apple Foundation classes
>> to iReports classpath so that you can use NSTimestamp in
>> your report template as a field class definition. Use the
>> same procedure to add the JodaTime jar to the iReport
>> classpath and thenuse the LocalDate class for the 'Field
>> Class' in the field Properties settings in iReport.
>>
>> To help you get concepts, note also the discussion about
>> BigDecimal and class cast exception around 42:15 on the
>> video timeline.
>>
>> HTH, Kieran
>>
>> PS. The fact that we *don't have to* use NSTimestamp and
>> that we can use java.util.Date as a field class type insdie
>> iReport is because NSTimestamp EXTENDS java.util.Date.
>>
>>
>> On Jan 31, 2011, at 6:57 AM, Theodore Petrosky wrote:
>>
>>> Paul,
>>>
>>> Thank you for looking at my attempts.
>>>
>>> I am using the JasperReports example that Kieran
>> Kelleher created for WOWODC 2010 as my starting point. It is
>> helpful not only for the beginning steps for integrating JR
>> but figuring out iReport to create the report templates.
>>>
>>> He mentions in the presentation that there will be a
>> fuller example committed to Wonder and perhaps this issue is
>> already addressed. However, in the meantime, I will continue
>> reading the limited documentation on JasperReports and
>> follow the code to see if I can figure out why I get this
>> error.
>>>
>>> Of course if I just forget about the date resolution
>> issue and use timestamps the issue goes away, but I have to
>> deal with my app refusing to work when I switch platforms.
>> So I could spend the time learning the methods of getting
>> around the Java dateTime issues.
>>>
>>> Thanks again.
>>>
>>> Ted
>>>
>>>
>>> --- On Mon, 1/31/11, Paul Hoadley <email@hidden>
>> wrote:
>>>
>>>> From: Paul Hoadley <email@hidden>
>>>> Subject: Re: JasperReport LocalDate question
>>>> To: "Theodore Petrosky" <email@hidden>
>>>> Cc: "WebObjects-Dev Mailing List List" <email@hidden>
>>>> Date: Monday, January 31, 2011, 3:52 AM
>>>> On 31/01/2011, at 12:01 AM, Theodore
>>>> Petrosky wrote:
>>>>
>>>>> So my attempt is to add into LocalDate the
>> extends
>>>> like this:
>>>>>
>>>>> public class LocalDate extends
>> java.util.Date
>>>> implements ReadablePartial,
>> Comparable<Object>
>>>>> {
>>>>>
>>>>> }
>>>>
>>>> I don't think you need or want to do this. I
>> don't
>>>> think your LocalDate wrapper (which, for those who
>> haven't
>>>> looked at Henrique's example, just extends
>> java.lang.Object,
>>>> implements ReadablePartial,
>> Comparable<Object>, and
>>>> contains a private field of type
>> org.joda.time.LocalDate)
>>>> should be a subclass of Date, which is a
>> full-resolution
>>>> timestamp type.
>>>>
>>>>> but then there is an error:
>>>>>
>>>>> - The interface Comparable cannot be
>> implemented more
>>>> than once with different arguments:
>> Comparable<Date>
>>>> and
>>>>>
>>>> Comparable<Object>
>>>>>
>>>>> so I checked the docs on java.util.Date:
>>>>>
>>>>> public class Date
>>>>> extends Object
>>>>> implements Serializable, Cloneable,
>>>> Comparable<Date>
>>>>>
>>>>> so he implements Comparable<Date> but
>> LocalDate
>>>> had Comparable<Object>.
>>>>>
>>>>> I hate this stuff. So I deleted Comparable
>> from
>>>> LocalDate and now there is an error with a
>> method:
>>>>>
>>>>> Name clash: The method compareTo(Object) of
>> type
>>>> LocalDate has the same erasure as compareTo(T) of
>> type
>>>> Comparable<T> but does
>>>>> not override it
>>>>>
>>>>> I made the executive decision to comment out
>> the
>>>> compareTo() method in LocalDate.
>>>>>
>>>>> And to my complete surprise, it works.
>>>>
>>>> Unfortunately, that's likely to be just some good
>>>> luck. It may well work in this case, but it
>> doesn't
>>>> seem right to me (or necessary). I would go
>> back and
>>>> ask why JasperReports is _expecting_ to be able to
>> cast some
>>>> value to a Date.
>>>>
>>>>
>>>> --
>>>> Paul.
>>>>
>>>> http://logicsquad.net/
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be
>> ignored.
>>> Webobjects-dev mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>>
>
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden