Re: Help! Have array of EOs. Need convert to CSV (selected key paths)
Re: Help! Have array of EOs. Need convert to CSV (selected key paths)
- Subject: Re: Help! Have array of EOs. Need convert to CSV (selected key paths)
- From: "Robert B. Hanviriyapunt " <email@hidden>
- Date: Sun, 14 Dec 2014 14:28:28 -0600
That's funny. After I sent my help message I just thought about it some and I ended up doing exactly as you mentioned. I found the headers settings somewhere and follow that as well. I also felt something in wonder to quote values as necessary for excel friendly CSV files.
Sometimes I freak out too early and send a help message and then find my answers right after on my own.
Sent from my iPhone
> On Dec 14, 2014, at 9:41 AM, CHRISTOPH WICK | i4innovation GmbH, Bonn <email@hidden> wrote:
>
> Hi Robert,
>
> Maybe this helps:
>
> 1. create a ordinary WOComponent, e.g. MyCSVComponent.wo
>
> In the HTML part, you don't write HTML (skip the whole "<html><body> ... </body></html>" stuff), but the CSV content you need:
>
> <wo:repeat list="$myList" item="$myItem">
> "<wo:string value="$myItem.property1" />", "<wo:string value="$myItem.property2" />" ...
> </wo:repeat>
>
> 2. in MyCSVComponent.java you override the method "appendToResponse" like this:
>
> public class MyCSVComponent extends ERXComponent {
>
> public String fileName;
> public NSArray<MyObject> myList;
> public MyObject item;
>
> // override appendToResponse to let the browser make a download,
> // instead of displaying the result in a brwoser window
> public void appendToResponse(WOResponse response, WOContext context) {
> // set the mimetype to csv
> response.setHeader("text/comma-separated-values", "content-type");
> // tell the browser to download the file instead of showing it in a window
> response.setHeader("attachment; filename=\""+fileName+"\"", "Content-Disposition");
>
> // create the response
> super.appendToResponse(response, context);
> }
> }
>
> where "fileName" is the name of the file you will give the download.
>
> In your master page, create a link like this:
>
> <wo:link action = "$downloadCSVAction">download CSV</link>
>
> and in the Java-Code of your master page
>
> public WOActionResults downloadCSVAction() {
> MyCSVComponent nextPage = (MyCSVComponent) pageWithName(MyCSVComponent.class);
> nextPage.myList = ... // set the list to an NSArray of whatever you need
> nextPage.fileName = ... // set the fileName to whatever you need
> return nextPage;
> }
>
>
> Does this answer your question?
>
> C.U.CW
> --
> The three great virtues of a programmer are Laziness, Impatience and Hubris. (Randal Schwartz)
>
>> On 13.12.2014, at 21:59, Robert B. Hanviriyapunt <email@hidden> wrote:
>>
>> Help! I need some advise on how to EASILY accomplish the following:
>>
>> have array of ERXKey(Path)s for columns to report
>> have array of EOs
>> must make wo:link's action respond with CSV (browser to download, not display in browser)
>>
>> what is the easiest way (i’m hoping it’s not D2W unless it make it really easier)
>>
>> please a quick demo solution somewhere would be awesome!
>>
>> = Robert =
>> _______________________________________________
>> 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