PDA

View Full Version : [3.1] Ext.Direct.Store issue...Please Help!



AndreaCammarata
14 Jan 2010, 2:40 PM
Hi guys.
I'm working on my ux.FileView (http://www.extjs.com/forum/showthread.php?t=89507) and I decided to use Direct functionality.
I read a loooot of post on the forum but noone really help me, i'm not figuring out how to correctly use the Ext.data.DirectStore.
Let's begin to say that i'm using Ext 3.1 and, server side, the Ext.Direct .Net Server-side stack. (http://extjs.com/forum/showthread.php?t=68161)

The code on the server is simple:
(I simplified for better understand the real problem)


namespace Aral.Modules.DiskManager
{
[DirectAction]
public class DiskManager : DirectHandler
{
private HttpServerUtility Server = HttpContext.Current.Server;

public override string ProviderName
{
get { return "Ext.app.REMOTING_API"; }
}

public override string Namespace
{
get { return "Aral"; }
}

[DirectMethod]
public string GetFiles(string Path)
{
return Path;
}
}
}
Client side, after i add the provider with the following lines


Ext.onReady(function() {

Ext.Direct.addProvider(Ext.app.REMOTING_API);

});I'm able to call my DirectMethod without any problem with firebug.


Aral.DiskManager.GetFiles('Hello World!', function(data, e){
console.log(data);
});The real problem is that i have to use it binded to my Ext.Direct.Store, so, i tried to configure it in different ways:

Configuration 1:

this.fileStore = new Ext.data.DirectStore({
storeId: 'fileStore',
paramsAsHash: false,
baseParams: {
'Path': 'Hello World'
},
api: {
load: Aral.DiskManager.GetFiles
},
fields: [
{ name: 'id', type: 'string' }
]
});Output:

uncaught exception: Ext.data.DataProxy: DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration.Configuration 2:

this.fileStore = new Ext.data.DirectStore({
storeId: 'fileStore',
paramsAsHash: false,
baseParams: {
'Path': 'Hello World'
},
directFn: Aral.DiskManager.GetFiles
fields: [
{ name: 'id', type: 'string' }
]
});Output:

{"type":"exception","tid":2,"action":"DiskManager","method":"GetFiles","result":null,"message":"Parameters length does not match"}Configuration 3:

this.fileStore = new Ext.data.DirectStore({
storeId: 'fileStore',
paramsAsHash: true,
baseParams: {
'Path': 'Hello World'
},
directFn: Aral.DiskManager.GetFiles
fields: [
{ name: 'id', type: 'string' }
]
});Output:

{"type":"exception","tid":2,"action":"DiskManager","method":"GetFiles","result":null,"message":"Error occurred while calling Direct method: A 'System.Object' can't be converted in a 'System.String'."}At this point I don't really know how to configure it.
Does someone is able to give me a hand?
Thanks to everyone will reply ~o)

AndreaCammarata
15 Jan 2010, 8:01 AM
Hi guys! No one can help me?
I really need a hand.

cerad
15 Jan 2010, 11:20 AM
In your first example you mapped 'load'. 'load' is only used for forms. It should be 'read'.

Here is a working store:


var gridStore = new Ext.data.DirectStore
({
api:
{
read: Zayso.Direct.Referee_RefereeScheduleSearch.read
},
// These all come from Store
storeId : 'referee-schedule-grid-store',
autoLoad : false,
remoteSort : false,

// These from the reader
root : 'records',
idProperty : 'id',
totalProperty : 'totalCount',
successProperty : 'success',
messageProperty : 'message',
fields : recordFields
});

And the api:


Zayso.Direct.API = function()
{
var api =
{
url : 'direct.php',
type : 'remoting',
namespace : 'Zayso.Direct',
actions :
{
Referee_RefereeScheduleSearch:
[
{ name: 'read', len: 1 }
]
}}};

I always use paramsAsHash = true (default). This way all the params end up in one argument. Stay away from directfn. never seems to work as expected.

AndreaCammarata
17 Jan 2010, 10:35 AM
Hi cerad, thank you for you reply.
You was right, i used load instead read method from the api configuration, that was my mistake. I read your example, but i don't found the way you pass the params to the server.
You api configuration, in fact, accept one argument, but you don't set it. How does it work? Do you know a way to do that? If you see my examples i set the baseParams but id doesn't work.
Thanks cerad.

cerad
18 Jan 2010, 8:41 AM
In most cases I set the parameters during load.
store.load({params: {whatever}});

But baseParams seems to work fine for me as well.

Here is an example of a posted request:
{
"action":"Referee_RefereeSignupCombo",
"method":"read",
"data":[{"member_id":27}],
"type":"rpc","tid":4
}

The data element will end up containing one array with however many parameters you pass.

AndreaCammarata
18 Jan 2010, 9:17 AM
That's good!
I will test it in one hour.
Meantime, which version of ext framework and Direct Router are you using?

cerad
18 Jan 2010, 9:27 AM
ExtJS 3.1.0

I'm using my own PHP base router. The samples provided were a bit obscure for my taste. Building my own was a key step to understanding what was going on.

dancardillo
19 Jan 2010, 2:49 PM
Andrea, I am interested to see what you are able to come up with. I was looking at this a while ago, and was unable to get any of the suggested methods to work with the .Net Router, in passing arguments to a server function to load a DirectStore. I have just started researching it again, and need a working example to figure out what is wrong with my code.

AndreaCammarata
19 Jan 2010, 3:32 PM
Hi cerad, thanks for your suggestions.
Unfortunately the problem seems to be with .net router I'm using, in fact, dancardillo seems to have the same problem I faced.
Anyway, i'm implementing the .net router stack developed by Evant with gooood result.
I hope to end this in a couple of hours, than I write down some examples and i will release it for the community. By Using this .net router, you will be able to call direct functions with named parameters and populate Direct.Stores without any changes needed client side on ext framework.
I really hope to complete the first release in this week but first...i need a coffee ~o);).
Meantime you can read a short brief to this post (http://www.extjs.com/forum/showthread.php?t=88393).

dancardillo
19 Jan 2010, 4:20 PM
Andrea,
I was able to get a modified version of Evants Router to work with Ext 3.0.3 using directFn calls, and parameters, hope this helps. I look forward to your implementation to make this more robust...

Data Store:

var ds = new Ext.data.DirectStore({
paramsAsHash: false,
paramsNames: {
uid: "uid"
},
paramOrder: 'uid',
baseParams: { uid: 22 },
root: '',
directFn: MyApp.Handler.GetData,
idProperty: 'id',
fields: [
{ name: 'id' },
{ name: 'fullname' },
{ name: 'first' }
]
});


Load DataStore:


ds.load();


API:


[DirectMethod]
publicJArray GetData(Int64 uid)
{
DataClassesDataContext db = newDataClassesDataContext();
var dsUser = from u in db.users
where u.ID == uid
selectnew
{
id = u.ID,
fullname = u.FirstName + ' ' + u.LastName,
first = u.FirstName
};

JArray json = JArray.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(dsUser, Formatting.Indented));
return json;
}