• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: FOSS Reporting Libraries?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FOSS Reporting Libraries?


  • Subject: Re: FOSS Reporting Libraries?
  • From: John Ours <email@hidden>
  • Date: Tue, 08 Sep 2009 09:59:55 -0400

I can't find that old sample anywhere. The meat of it is the WCJRDataSource I sent earlier though - it doesn't have any other dependencies beyond the obvious Jasper and WO; WCJRUtils is just a few utility methods that I put in the body of my last message. It's attached here.

I don't have time to build out a sample right now, but hopefully this will help (compiling and debugging left as an exercise for the reader...I'm just copying in code from an old project):


1. Include WCJRDataSource.java and WCJRUtils.java in your project. You'll need to reference jasperreports-x.x.x.jar, I'm using 3.5.0.



2. That class is a wrapper for an NSArray<T> that holds the EOs for your report. You can instantiate it like this:


	private WCJRDataSource getPersonDataSource() {
		EOEditingContext ctx = someContext;
		NSArray<Person> people = Person.fetchByState(ctx, "OH");
		return new WCJRDataSource(people);
	}


3. Create a report using Jasper's iReport product. The trick here is that you have to create your fields with underscores ("_") to delineate the key path instead of dots ("."). So in the above example I have an array of People....if I want to access the city of the primary address, I create the field called primaryAddress_city. If I want a property of the EO itself, like lastName, then no underscore is required. Just take the same expression you would use in a WOD file and replace the periods with underscores.


A screenshot of one of my reports in iReport is attached.


4. Save the report to a folder called Reports in the Resources directory of your WO project. WCJRUtils is hard coded to look there since....well that's where I put my reports ;)



5. Run the report using something like this in a WOComponent, which will compile the report, run it as a PDF to a byte array, and return the PDF to the client:


    public String fileName;
    private byte[] pendingResponse;

public void appendToResponse(WOResponse aResponse, WOContext aContext) {
super.appendToResponse(aResponse, aContext);
if (pendingResponse != null) {
ByteArrayInputStream in = new ByteArrayInputStream(pendingResponse);
aResponse.setHeader("application/pdf", "Content-type");
aResponse.setHeader("inline; filename=" + fileName, "Content- disposition");
aResponse.setContentStream(in, 512, (long)pendingResponse.length);
}
}


    public void doReport() {
		WCJRDataSource ds = getPersonDataSource();

		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("someParameter", someValue);

pendingResponse = WCJRUtils.runReportToPDF("MyNewReport", params, ds);
}




Attachment: WCJRDataSource.java
Description: Binary data

Attachment: WCJRUtils.java
Description: Binary data

PNG image





On Sep 8, 2009, at 12:24 AM, Joe Little wrote:

On Sun, Sep 6, 2009 at 10:04 PM, Cheong Hee (Gmail) <email@hidden> wrote:
Hi Kieran

Besides, I guess also you need to have WCJRUtils.java and
WCReportsScriptlet.java. Some time back (~2007) I was able to download a
zip sample called WOCodeJasperSample. Just ran through the sample code test
and it worked. If interested, I could post it over.



Can you send a link to WOCodeJasperSample? The typical search isn't finding it.


HTH.

It was called WCJRDataSource...I can't find it again on the web so
it's attached.


_______________________________________________ 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

 _______________________________________________
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

References: 
 >Re: FOSS Reporting Libraries? (From: "Cheong Hee (Gmail)" <email@hidden>)
 >Re: FOSS Reporting Libraries? (From: Joe Little <email@hidden>)

  • Prev by Date: Re: Starting a new Web App
  • Next by Date: Re: EOF inheritance
  • Previous by thread: Re: FOSS Reporting Libraries?
  • Next by thread: Re: FOSS Reporting Libraries?
  • Index(es):
    • Date
    • Thread