Hi Stéphan,
Yes, it is possible to work with NSKeyValueCodingAdditions objects
(EO's, NSDictionary, etc.). Working with EOs is what makes it really
useful in a WO-like way.
There is a tentative plan to have a full or half session on
JasperReports integration with WO at WOWODC 2010. I asked about JR 2
months ago and got a few good pointers and example code from John Ours.
Here is a quick summary of approach.
Build the report, either hand-coding the XML (which is tedious), or
use iReport (which works directly with standard JRXML files). However,
I recommend reading, if not at least skimming, thru Heffelfinger's
book to understand the XML file sections. In iReport you can switch
between graphical view and XML view. I used latest 3.6.0 JasperReports
and iReport.
For keyvaluecoding report content, define field names in the report as
keypaths, BUT using "_" instead of ".". Use underscores instead of
periods. You can use some other character too if you like, but periods
don't work as field names.
Design the report, adding summary groups, nested subsummary groups, etc.
My recommendation is to COMPILE the report (Compile menu command in
iReport ... can be done in java on the fly or with ant as part of
build.xml too if you like). Compiling the report validates the XML
file, syntax, positioning and size of all elements and converts it to
an efficient binary format that JasperReports understands. Some others
compile on the fly, and/or compile and cache the compiled report in
the app, however if your template has a mistake, compilation will
fail... which is really bad in production The second reason I
recommend compiling in advance is that it can take 30 to 60 seconds to
compile a report whereas it may take on a few seconds to run the
report using the compiled template. The more data in the report, the
longer it will take to run, so from the outset, consider architecting
this to run as a long response process that returns the downloadable
file.
Using a JRXML template with EOs has a few steps:
1) Define a JRDataSource class that provides report objects ("detail")
objects to the JR engine. This JRDataSource class is basically a
custom iterator that can simply be a wrapper on an NSArray of
KeyValueCoding objects, or for huge sets of EO's can use an
ERXFetchSpecificationBatchIterator internally to provide objects in a
memory efficient way.
2) Run the report using the JRDataSource and the (compiled) jasper
template. The jasper templates would generally be stored in the
project or framework Resources dir.
JR also allows for a HashMap dictionary of "Report Parameters" which
is the 3rd parameter to the utility methods that run a report (1.
compiled report, 2. JRDataSource, 3. Report Parameters hashmap). These
can be used in report expressions to do whatever you want. For example
you could have a "devMode" boolean entry that would include debug
information in the generated report. or a "userType" key that might
conditionally render a some outer summary grouping for management
roles that is not normally rendered for a different user.
Additionally, you can define a custom "Scriptlet" class which can
provide custom "functions" to the reporting engine. An example of this
is to provide methods that take a NSTimestamp object and return a
formatted String for actually display in the report.
The iReport tool is java and runs on Mac and Windows. It is a NetBeans
platform app. However I found that the Properties view in the Mac did
not render the selected values. So I ran the Windows version in
Parallels and directly edited the jrxml template in my Mac eclipse
workspace through a parallels "network drive" share of my Mac home
dir. Scrolling some views on Windows made the view show garbled stuff
until I refreshed it ...... not sure if this was Parallels, iReport,
NB platform issue or what. Still a new version iReport 3.6.1 is out
that I have not upgraded to yet which might fix those cosmetic GUI
issues. In iReport, you can link foundation jar or your project/
framework's bin dir to the environment classpath in iReport
preferences so that you can refer to things like NSTimestamp and/or
understand the symbols in your custom Scriptlet class that is
referenced in the report.
Conceptually the "detail" section of the report relates to the objects
(EOs, KeyValueCoding objects). The field names are keypaths (periods
replace with underscores) that connect the fields to your EOs. You can
add a report group around the detail and another around that, and
another around that, etc. each group has a header and footer section.
Those can contain field values, static text, summary values, custom
expressions. You can create expressions in java (also groovy, etc.).
Rendering of the Detail, Group Header, Group Footer, and other "bands"
of the report are optional and can have conditional expressions to
render them or not dynamically. For example a group summary might want
to be rendered when there are more than one detail EOs in the
group ... easily done.
John Ours email that got me started can be found here.... (thanks John)
http://osdir.com/ml/webobjects-dev/2009-09/msg00194.html
(find it on webobjects-dev archive for the thread ...... search seems
to suck on webobjects-dev)
...... although I have modified the code and built a few reusable
classes for the mundane handling of the long response and report
download. My classes need to be refined further to be more generic and
useful to the community and I plan to create a framework,
documentation and an example app for WOWODC to make it really easy for
anyone to easily add downloadable PDF reports to their apps.
BTW, as well as PDF, the reports can be also output as HTML, Excel,
RTF, CSV, etc. Obviously PDF is more readable for classic reports with
nested summaries whereas CSV, excel are practical for output where
each line is a detail or the same summary group.
Spend the $35 for "JasperReports 3.5 for Java Developers" on amazon as
a reference book to have ....... you will waste way more expense
guessing and figuring this out on your own IMHO.
HTH, Kieran
On Nov 3, 2009, at 2:58 AM, Mertz Stéphan wrote:
Hello Kieran,
Could you share with us the way in which you integrated jaspereport
with WebObjects?
Is it possible to use KVC and the objets graph like ReportMill ?
Thank you very much.
Stéphan
Le 3 nov. 2009 à 02:35, Kieran Kelleher a écrit :
Dennis,
It is beneficial to have sessions on the few frameworks that are
available.... I am sure each has strengths and benefits. I only
mentioned Jasper Reports because I recently absorbed it into my
head and integrated it into an app easily and I was very pleased
with the results. I could not compare it to PDFKit because I have
not used it .... yet.... although I did browse the PDFKit
documentation.
I would love to hear a session on your PDFKit framework. The WOWODC
sessions are always a great springboard to dive into something one
has not used before.
Regards, Kieran :-)
On Nov 2, 2009, at 5:56 PM, Gaastra Dennis - WO Lists wrote:
It appears that several people on this list are promoting all
kinds of other PDF generating frameworks, for whatever reasons
they have.
We were proposing to present at the WOWDC on how to make some
advanced PDF reports that cannot be created with the regular
template systems; with a fair amount of new example code.
However, if this appears not to be of benefit to most of the
community, maybe we should focus on presenting the other items.
With Kind Regards,
Dennis Gaastra,
Chief Technology Officer,
WEBAPPZ Systems, Inc.
On 2009-11-02, at 1:42 PM, Kieran Kelleher wrote:
Ricardo,
JasperReports ..... Free, OpenSource..... it works ..... easy,
peasy....... only thing u have to do is buy JasperReports 3.5 for
Java Developers from amazon.com since there is no easy to find
free documentation ..... yet ;-)
Regards, Kieran
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com