PDA

View Full Version : PollProvider with Ext.Direct



gurufaction
12 Jun 2009, 11:35 AM
According to the documentation you can specify an Ext.Direct method via the 'url' property but my entire application fails to render and I just get a blank screen. If I enclose the url in single quotes it works but I get 404 error because the page doesn't exist which is expected. I'm I missing a configuration inorder to tell the polling provider that the url is a function not a string?



Ext.Direct.addProvider(Ext.app.REMOTING_API,{
type:'polling',
url: Transmission.getList,
id: 'transmission-poll',
baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""}
}
);

mjlecomte
12 Jun 2009, 11:54 AM
what is the value of Transmission.getList?

mjlecomte
12 Jun 2009, 11:54 AM
And what 'documentation' are you looking at specifically?

gurufaction
12 Jun 2009, 1:01 PM
Transmission.getList is a class.method from my Ext.Direct ServerSide Stack. Here is the documentation (http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.direct.PollingProvider)

ckr
20 Jun 2009, 1:51 PM
It can be a URL, as seen in various examples, or a client function (which at some point would make a connection to the server). Not a server side method. If it were server side then it would be an RPC and therefore a part of the Remoting Provider not a Polling Provider.

Create some function in your code that does an Ext.Ajax.request, and then define that function in your Polling Provider, and it should work.

Something like:


function myTestFunction(myBaseParams)
{
Ext.Ajax.request(
{
extraParams: myBaseParams,
url: 'yourServerURL.php',
success: function(response, params)
{
console.log(response.responseText);
}
});
}


And then your Polling Provider would be something like:


Ext.Direct.addProvider(Ext.app.REMOTING_API,{
type:'polling',
url: myTestFunction,
id: 'transmission-poll',
baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""}
}
);


Hope this helps!

dj
25 Jun 2009, 2:55 AM
According to the documentation you can specify an Ext.Direct method via the 'url' property but my entire application fails to render and I just get a blank screen. If I enclose the url in single quotes it works but I get 404 error because the page doesn't exist which is expected. I'm I missing a configuration inorder to tell the polling provider that the url is a function not a string?



Ext.Direct.addProvider(Ext.app.REMOTING_API,{
type:'polling',
url: Transmission.getList,
id: 'transmission-poll',
baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""}
}
);



That's probably a scope-issue. By assigning Transmission.getList to url you loose the scope information inside the getList method. Try this


Ext.Direct.addProvider(Ext.app.REMOTING_API,{
type:'polling',
url: Transmission.getList.createDelegate(Transmission),
id: 'transmission-poll',
baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""}
}
);



More on scope: http://extjs.com/learn/Tutorial:What_is_that_Scope_all_about / http://extjs.com/learn/Tutorial:What_is_that_Scope_all_about2

ckr
25 Jun 2009, 2:01 PM
Hmmm..... :-? Maybe I am confused here.

But it seemed like the OP was trying to setup the API for the first time. So unless that particular server side function is already defined, how would you specify a server side function in your API definition? Is that not what the API is for, to define the server side functions and what URL to use to get to the server or a client side function that will resolve the connection to the server?

For instance, in the remoting API, you specify the URL, which is typically your router on the server side. How could you specify the URL (router) with a server side function, when that server side function itself has to use the URL (router) that you are trying to define? Kind of like the horse before the cart?

In addition, when you call a server side function, you typically need a call back function.


Transmission.getList("whatToGet", function (result, e)
{
//do something clever when the server eventually responds...
});



Maybe I am missing what the OP was attempting to do, but I think he was just getting confused on what it was he needed to provide the API and not a scoping issue. But I could be wrong.

gurufaction
26 Jun 2009, 5:47 AM
I thought Direct Polling Provider supported direct methods similar to DirectStore's directFn property. That's the impression I got from the documentation.



url (http://extjs.com/forum/../deploy/ext-3.0-rc2/docs/source/PollingProvider.html#cfg-Ext.direct.PollingProvider-url) : String/Function
The url which the PollingProvider should contact with each request. This can also be an imported Ext.Direct method which will accept the baseParams as its only argument.


var store = new Ext.data.DirectStore({
storeId:'transmissions',
directFn: Transmission.getList,
remoteSort: true,
paramOrder: ['start','limit','sort','dir','query'],
root: 'data',
fields: [{
name: 'id',
type: 'int'
},
'customer',
'extension',
'communication',
'value',
'user',
{name: 'created', type: 'date', dateFormat:'Y-m-d H:i:s'},
{name: 'scheduled', type: 'date', dateFormat:'Y-m-d H:i:s'},
'delivered'
],
listeners: {
exception : function(proxy, type, action, options, res, arg) {
if (type === 'remote') {
Ext.Msg.show({
title: 'REMOTE EXCEPTION',
msg: res.message,
icon: Ext.MessageBox.ERROR
});
}
}
}
});

dj
27 Jun 2009, 2:38 AM
The relevant part of PollingProvider.js:


if(typeof this.url == 'function'){
this.url(this.baseParams);
}else{
Ext.Ajax.request({
url: this.url,
callback: this.onData,
scope: this,
params: this.baseParams
});
}


What PollingProvider does support: If url is a function, it gets periodically executed. No success or error checking is done in this case. PollingProvider does not fire 'data' or 'exception' events. The function gets the baseParams as only argument. This function could easily be a function accepting one argument that was generated from a RemotingProvider. All that PollingProvider does in this case is calling this function periodically. Collecting the data or handling exceptions has to be done with event-handlers attached to the RemotingProvider.

If that is what you want/need, try to defer the adding of the PollingProvider for some time. Maybe there is some weird timing issue going on:


Ext.Direct.addProvider(Ext.app.REMOTING_API);
(function(){
Ext.Direct.addProvider({
type:'polling',
url: Transmission.getList,
id: 'transmission-poll',
baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""}
}
);
}).defer(1000);

ckr
27 Jun 2009, 5:23 AM
I agree with DJ, that it would have to be handled with event-handlers.

Only problem, all RemotingProviders typically go through a router on the server, and a RemotingProvider by it's nature returns a type rpc. Which would mean you would have to write something special to handle that.

Since you are successfully calling a RemotingProvider function, the router should return type rpc. The only time it would not would be an exception on the server. So you would have to alter the logic back at the sever to know that the RemotingProvider function was actually called by a PollingProvider, and that the router should return a type exception, so that the event and message could be handled.

Seems a bit cloudy to me on how you use a RemotingProvider function for a Polling Provider. I guess that is why in my first post I broke it out into a client side function, so that you can handle the data and the success or failure.


That make sense DJ?

dj
28 Jun 2009, 4:15 AM
I also think that using a RemotingProvider function in a PollingProvider is a bit cloudy. Having a look at the documentation (e.g. "This event has not yet been implemented.") brings me to the conclusion that the PollingProvider is not finished yet. The most annoying thing I see is that the data and exception events of the PollingProvider are not fired when you use a (RemoteProvider) function as url config parameter.

Let's see how the PollingProvider will look like in the final release.