Convert queries for ext

6 views
Skip to first unread message

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 6:01:15 AM1/12/12
to ColdFusion Technical Talk

Hi, I am using a cfc that converts queries to ext grid. When I run the code keep getting error. Would appreciate any help on this issue:

'Unable to parse the JSON returned by the server: You're trying to decode an invalid JSON String:’

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349422

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 6:22:46 AM1/12/12
to ColdFusion Technical Talk

Can you show us a snippet of what you trying to do?

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349423

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 6:52:41 AM1/12/12
to ColdFusion Technical Talk

To, If you're using that CFQueryReader Ext package, then you want to use
ColdFusion's json serialization of the native query object. You want to
read that documentation thoroughly, and probably look at the sample code
in the download. The purpose behind the custom reader is to allow you to
work with CF without having to generate 'special' output from the server.

Steve 'Cutter' Blades
Adobe Community Professional
Adobe Certified Expert
Advanced Macromedia ColdFusion MX 7 Developer
____________
http://cutterscrossing.com


Co-Author "Learning Ext JS 3.2" Packt Publishing 2010
https://www.packtpub.com/learning-ext-js-3-2-for-building-dynamic-desktop-style-user-interfaces/book

"The best way to predict the future is to help create it"

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349425

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 7:05:55 AM1/12/12
to ColdFusion Technical Talk

Hi Andrew this is my store and ConvertQueriesForExt.cfc:

Ext.define('MyApp.store.UserStore', {
extend: 'Ext.data.Store',

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'UserStore',
proxy: {
type: 'ajax',
url: '/orm_2/view/user/app/store/ConvertQueriesForExt.cfc',
reader: {
type: 'json',
idProperty: 'name',
root: 'users'
}
},
fields: [
{
name: 'user_pk',
allowBlank:false,
type: 'int'
},
{
name: 'email',
sortType: 'asText',
type: 'string'
},
{
name: 'isactive',
type: 'boolean'
},
{
name: 'userroleid',
sortType: 'asInt',
type: 'int'
}
]
}, cfg)]);
}
});
----------------------------------------


<cfcomponent output="false">

<cffunction name="getUsers" access="remote" returnformat="json" output="false" hint="Gets list/detail of posts">
<cfargument name="limit" type="numeric" required="no">
<cfargument name="start" type="numeric" required="no">
<cfargument name="sort" required="no" type="string">

<cfset var userData = "">

<cfquery name="userData" datasource="orm_2">
SELECT user_pk,email,isactive,userroleid
FROM users
ORDER BY #arguments.sort#
</cfquery>

<cfset clist = 'user_pk,email,isactive,userroleid'>
<cfset arrayRecords = convertQueryToExtJSON(userData,clist,arguments.limit,arguments.start)>
<cfset s = {rows=arrayRecords,dataset=#userData.recordcount#}>
<cfreturn s />
</cffunction>

<cffunction name="ConvertQueryToExtJSON" returntype="any" access="public">
<cfargument name="query" type="query" required="yes" />
<cfargument name="clist" type="string" required="yes" />
<cfargument name="limit" type="numeric" required="yes" />
<cfargument name="start" type="numeric" required="yes" />
<cfscript>
arrayRecords = ArrayNew(1);
if(arguments.start==0) {
counter = 1;
}
else {
counter = arguments.start;
}
for(i=1;i<=arguments.limit;i++) {
strResults = structNew();
for(x=1;x<=listLen(clist);x++) {
strResults[ucase(listGetAt(clist,x))] = query[listGetAt(clist,x)][counter];
}
arrayRecords[i] = strResults;
counter = counter+1;
}
return arrayRecords;
</cfscript>

</cffunction>
</cfcomponent>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349426

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 8:38:16 AM1/12/12
to ColdFusion Technical Talk

Your problem lies in that you have not converted the Array to a JSon array,
therefore your Json is invalid.

Might I suggest using FireFox with with Firebug and / or Chrome console to
show us what your Json is being returned. I am convinced by looking at the
code that a Json Array is not being handled here.

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349433

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 9:14:12 AM1/12/12
to ColdFusion Technical Talk

Hi Andrew thanks for your reply and it is now return json format although my problem now is the data not shown in the grid. I would appreciate any help...

{"ROWS":[{"EMAIL":"s....@gosh.org.uk","USER_PK":"1","ISACTIVE":"1","USERROLEID":"1"}],"DATASET":"1"}

Thanks

Tom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349435

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 9:23:51 AM1/12/12
to ColdFusion Technical Talk

Unlike CFML, JavaScript is cAsE sEnSiTiVe, so you'll have to make sure that
the case of your keys match on both sides (e.g. CFML and JavaScript).

HTH

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349436

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 9:34:17 AM1/12/12
to ColdFusion Technical Talk

Hi Matt, can you please simplify your reply as I am new to extjs and coldfusion.

Thanks
Tom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349437

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 9:39:57 AM1/12/12
to ColdFusion Technical Talk

What Matt is saying is that ColdFusion will make everything uppercase, so
when you create the Grid and the key for binding will also need to be
uppercase.

If you post the code for a snippet of your Grid, we can show you what we
mean.

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349438

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:01:15 AM1/12/12
to ColdFusion Technical Talk

Hi Andrews, here is the code for my grid. Thanks Tom

-----------------------
Ext.define('MyApp.view.ui.UsersDetail', {
extend: 'Ext.panel.Panel',
style: "margin: 0px auto 0px auto;", // center the form panel
frame: true,
height: 450,
width: 410,
autoScroll: true,
layout: {
align: 'stretch',
type: 'vbox'
},
title: '<span class="gridPanelText">Users</span>',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
itemId: 'grid',
store: 'UserStore',
flex: 1,
columns: [
{
xtype: 'numbercolumn',
width: 40,
dataIndex: 'user_pk',
format: 0
},
{
xtype: 'gridcolumn',
width: 165,
dataIndex: 'email',
text: 'Email'
},
{
xtype: 'booleancolumn',
width: 80,
dataIndex: 'isactive',
text: 'Is Active'
},
{
xtype: 'numbercolumn',
width: 90,
dataIndex: 'userroleid',
text: 'Role',
format: 0
}
],
viewConfig: {

}
}
],
dockedItems: [
{
xtype: 'toolbar',
flex: 1,
dock: 'top',
items: [
{
xtype: 'button',
iconCls: 'addIcon',
text: 'Add'
},
{
xtype: 'button',
iconCls: 'editIcon',
text: 'Edit'
},
{
xtype: 'button',
iconCls: 'deleteIcon',
text: 'Delete'
},
{
xtype: 'tbseparator'
},
{
xtype: 'button',
iconCls: 'importIcon',
text: 'Import'
},
{
xtype: 'tbseparator'
},
{
xtype: 'button',
iconCls: 'exportIcon',
text: 'Export'
}
]
},
{
xtype: 'toolbar',
flex: 1,
dock: 'top',
items: [
{
xtype: 'textfield',
width: 323
},
{
xtype: 'tbspacer'
}
]
}
]
});

me.callParent(arguments);
}
});

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349442

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:04:54 AM1/12/12
to ColdFusion Technical Talk

Tom,

See these type of lines

dataIndex: 'email',

This tells the grid to index the data in the store, so in this case you
will need to make it

dataIndex: 'EMAIL',

Hope that helps.

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349443

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:15:59 AM1/12/12
to ColdFusion Technical Talk

You will also need to make sure that the class/ID names in the markup match
the cAsE.

HTH

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349447

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:44:42 AM1/12/12
to ColdFusion Technical Talk

Hi Andrew, thanks for your help

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349453

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:55:54 AM1/12/12
to ColdFusion Technical Talk

Hi Andrew,

Problem solved and thanks for all your help and support.

Tom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349456

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:56:24 AM1/12/12
to ColdFusion Technical Talk

Hi Matt,

Problem solved and thanks for all your help and support.

Tom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349457

hofar...@houseoffusion.com

unread,
Jan 12, 2012, 10:57:14 AM1/12/12
to ColdFusion Technical Talk

Hi Steve,

Problem solved and thanks for all your help and support.

Tom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|

Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349458

Reply all
Reply to author
Forward
0 new messages