Return Multi-Format (JSON, XML) Issue

319 views
Skip to first unread message

James Eisenlohr

unread,
Jan 26, 2012, 10:26:12 AM1/26/12
to taffy...@googlegroups.com
Working with the api_twoFormats example and I created a simple resource called configsCollection.cfc. I cannot get Taffy to return JSON when using the CustomRepresentationClass.cfc ... I haven't modified this cfc. For example, if I use either of the following URIs, I get back XML even though JSON is the default!


Here is my configsCollection.cfc:

<cfcomponent extends="taffy.core.resource" taffy:uri="/configs" hint="sends application configs">
<cffunction name="get" access="public" output="true">
<cfquery name="q" datasource="#application.dsn#">
select * from WAR_config
</cfquery>
<cfif q.recordCount gt 0>
<cfreturn representationOf(q).withStatus(200) />
<cfelse>
<cfreturn noData().withStatus(404) />
</cfif>
</cffunction>

</cfcomponent>

The only way I have been able to get JSON returned is if I comment out the setDefaultRepresentationClass call within the Application.cfc:

function configureTaffy(){
//setDefaultRepresentationClass("resources.CustomRepresentationClass");
}

Anyone else have this issue? Suggestions?

Adam Tuttle

unread,
Jan 26, 2012, 11:33:11 AM1/26/12
to taffy...@googlegroups.com
instead of "resources.customRepresentationClass" you should put in the dot-notation path to your actual custom representation class. :)

Adam

James Eisenlohr

unread,
Jan 26, 2012, 4:04:45 PM1/26/12
to taffy...@googlegroups.com
Adam,

I have updated the path to my CustomRepresentationClass.cfc. I am certain the path is correct and I'm still having the same issue. I get XML data back unless I comment out the call to the setDefaultRepresentationClass method.

Here is my Application.cfc:

<cfcomponent extends="taffy.core.api">
<cfscript>
this.name = hash(getCurrentTemplatePath());
function applicationStartEvent(){
application.dsn = 'outreach';
application.JsonUtil = createObject("component", "api.v1.resources.JSONUtil.JSONUtil");
application.AnythingToXML = createObject("component", "api.v1.resources.AnythingToXML.AnythingToXML");
}

function configureTaffy(){
setDefaultRepresentationClass("api.v1.resources.CustomRepresentationClass");
}
</cfscript>
</cfcomponent>

Here is my CustomRepresentationClass.cfc:

<cfcomponent extends="taffy.core.baseRepresentation">

<cfset variables.jsonUtil = application.jsonUtil />
<cfset variables.AnythingToXML = application.AnythingToXML />

<cffunction name="getAsJSON" taffy:mime="application/json" taffy:default="true" output="false">
<cfreturn variables.jsonUtil.serializeJson(variables.data) />
</cffunction>

<cffunction name="getAsXML" taffy:mime="application/xml" output="false">
<cfreturn variables.AnythingToXML.ToXML(variables.data) />
</cffunction>

</cfcomponent>

My configsCollection.cfc resource:

<cfcomponent extends="taffy.core.resource" taffy:uri="/configs" hint="sends application configs">
<cffunction name="get" access="public" output="true">
<cfquery name="q" datasource="#application.dsn#">
select * from WAR_config
</cfquery>
<cfif q.recordCount gt 0>
<cfreturn representationOf(q).withStatus(200) />
<cfelse>
<cfreturn noData().withStatus(404) />
</cfif>
</cffunction>

</cfcomponent>

Thanks,

James

Adam Tuttle

unread,
Jan 26, 2012, 10:50:13 PM1/26/12
to taffy...@googlegroups.com
Hm, whatever the problem is, it doesn't seem to be coming through in what we're talking about. Can you share a zip of the problem code? That way I can debug it locally and let you know what the issue is after I figure it out.

Adam

James Eisenlohr

unread,
Jan 27, 2012, 10:01:21 AM1/27/12
to taffy...@googlegroups.com
Thank you for your help, Adam!

I just tested this stuff using IE and Firefox in addition to Chrome... IE returns JSON and XML correctly when using .json and .xml at the end of the URI. However, Firefox and Chrome just return XML no matter what is appended to the URI. Weird? I have attached the files.

James
taffy-example.zip

AJ Mercer

unread,
Jan 27, 2012, 6:35:43 PM1/27/12
to taffy...@googlegroups.com

Adam Tuttle

unread,
Feb 8, 2012, 9:35:05 AM2/8/12
to taffy...@googlegroups.com
Just wanted to follow up. I was out of the country for the last week or so and am still settling back in and catching up. I will get to this asap!

Adam

James Eisenlohr

unread,
Feb 9, 2012, 9:52:36 AM2/9/12
to taffy...@googlegroups.com
Still having same issue using ACF. No javascript errors are appearing in Chrome's javascript console... everything works well using Railo though. However, at work, ACF is used.

Adam Tuttle

unread,
Jul 11, 2012, 4:38:23 PM7/11/12
to taffy...@googlegroups.com
Hi James,

Just curious, have you updated to the latest version of Taffy? 1.1 was officially released recently. Curious if that might resolve it.

Adam

Joseph Higgins

unread,
May 1, 2014, 11:50:53 PM5/1/14
to taffy...@googlegroups.com
I have been looking for a custom renderer to account for the totalrecords needed by a paging grid control in ExtJs. what you posted looks exactly like what I need. I found it hard to believe after just into 4 days of ExtJS/Taffy/Coldfusion I have not found a CFC out there that demonstrates best practices for a rest CFC that will handle both list, combobox and grid paging requests. I had one that I used in ExtJS 2-3 that I was refactoring, but could not figure out how to override the default query renderer in Taffy.

Since you have overcome this, can you post a working example? I will otherwise take what you have started here and build on it.
Reply all
Reply to author
Forward
0 new messages