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 protected]>
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 protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/cw%40i4innovation.de
>
> This email sent to [email protected]
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
