event.renderData is always empty

60 views
Skip to first unread message

Jeff Willener

unread,
Oct 4, 2016, 12:51:56 PM10/4/16
to ColdBox Platform
I'm creating a RESTful API starting with the RESTful template.  Can someone tell me why when I use event.renderData always returns empty data?

Here my simple handler:

function years( event, rc, prc ) {

        // This is the format we want!


        var test = [

                {name="Tricia", lastname="Smith", nickname="Trish"},

                {name="Jack", lastname="Doe", nickname="JJ"}

];

        //prc.response.setData(test); // this works!

        event.renderData( type="json", data=test ); // this never works.


}


event.renderData always returns this below regardless if I use a Query variable, struct or database Query.

{
errorcode: 0,
error: false,
data: "",
messages: [ ]
}

Luis Majano

unread,
Oct 4, 2016, 9:45:50 PM10/4/16
to ColdBox Platform
Because the rest template leverages the response object used in the base handler. Basically there is no need to leverage render data explicitly. 

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057




--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/ec2d8f86-271f-4f6e-bb29-8e51b8467ae6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Willener

unread,
Dec 20, 2016, 1:09:51 PM12/20/16
to ColdBox Platform
Hi Luis,

I'm back to this same issue.  I want to render data back as JSON, XML, TEXT, HTML, etc. (see Rendering Data with Formats: http://wiki.coldbox.org/wiki/EventHandlers.cfm)

How can my REST api return back a data download file?

Thanks,

Jeff

Luis Majano

unread,
Dec 22, 2016, 7:59:36 AM12/22/16
to coldbox

On Tue, Dec 20, 2016 at 7:09 PM, Jeff Willener <jeffc...@gmail.com> wrote:
ST api return back a data download file?

You mean, deliver a file?

Luis F. Majano
CEO
Ortus Solutions, Corp

Jeff Willener

unread,
Dec 22, 2016, 11:15:53 AM12/22/16
to ColdBox Platform
Yes, return a file from the REST handler.  I'd like to return a query result in a csv formatted file as a download.  I think they'll want the json as well but not wrapped in the typical response and just the data section.  However I have tried to implement per the documentation and it only returns empty JSON.

Client wants this change pretty quick; really appreciate the help.

Thanks,
Jeff

Jon Clausen

unread,
Dec 22, 2016, 11:32:58 AM12/22/16
to col...@googlegroups.com

Jeff,

 

You’ll need to send custom headers for that download anyway.  Easiest do in a one-off handler method that delivers the spreadsheet and add a conditional in the current action to deliver the file if the flag is passed.  There’s a `downloadFile` method in this “QueryToCSV” helper, should get you started (though it performs an immediate flush/abort ):

 

https://gist.github.com/jclausen/8429aba7672185421e743554657b34dd

 

Jon

--

--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

Jeff Willener

unread,
Dec 22, 2016, 7:37:32 PM12/22/16
to ColdBox Platform
Thanks Jon, very appreciated.  I think I can get started with the QueryToCSV, thanks for that.  As for the handler, how would I call downloadFile(filePath)?  How far off is this example where my Route points to this function below?  I'm not sure what to return.  Also, I don't think QueryToCSV takes the Query object right?

function DataDownloadHandler(event, rc, prc) {
  queryService = new Query();
  queryService.setDatasource("myDb");
  queryService.setSQL(myQueryString)"

  fileToDownload = QueryToCSV(queryService,"DataFile",true);

  // Seems more needs to happen here...
  downloadFile(fileToDownload);
Reply all
Reply to author
Forward
0 new messages