PDA

View Full Version : [CLOSED] Cannot override buildUrl in a proxy



BillHubbard
7 Nov 2011, 3:26 PM
If I try to override the buildUrl method in a proxy, it does not work, because calling this.callParent(request) from within the override attempts to call buildRequest from parent class Ext.data.proxy.Proxy, which does not exist.

uncaught exception: this.callParent() was called but there's no such method (buildRequest) found in the parent class (Ext.data.proxy.Proxy)
msg = "this.callParent() was called but there's no such method (buildRequest) found in the
sourceClass = "Ext.data.proxy.Ajax
sourceMethod = "buildRequest"




proxy = {
type: 'ajax',
noCache: false,
pageParam: undefined,
limitParam: undefined,
startParam: undefined
url: '/Saba/api/platform/mobile/resources/',
reader: {
type: 'json',
root: 'list'
},
buildUrl: function(request) {
return this.callParent(request);
}
}

mitchellsimoens
8 Nov 2011, 9:58 AM
Not sure if it will work but how about this.callOverridden(arguments) ?

oncethor
24 Jan 2012, 9:59 AM
"this.callOverridden()" does not work either. This is the stack trace with Chrome 18.0 on Win 7 x64 and extjs 4.0.7.

Uncaught TypeError: Cannot call method 'apply' of undefined

Base.callOverridden ext-all-debug.js:2912 (http://localhost/fcs/extjs/ext-all-debug.js)
Ext.create.proxy.buildUrl EuStats.js:80 (http://localhost/fcs/EuStats.js)
Ext.define.buildRequest ext-all-debug.js:25856 (http://localhost/fcs/extjs/ext-all-debug.js)
Ext.define.doRequest ext-all-debug.js:26056 (http://localhost/fcs/extjs/ext-all-debug.js)
Ext.define.read ext-all-debug.js:25825 (http://localhost/fcs/extjs/ext-all-debug.js)
Ext.define.load ext-all-debug.js:44665 (http://localhost/fcs/extjs/ext-all-debug.js)
Base.callParent ext-all-debug.js:2891 (http://localhost/fcs/extjs/ext-all-debug.js)
Ext.define.load ext-all-debug.js:45280 (http://localhost/fcs/extjs/ext-all-debug.js)
(anonymous function)

The code is from the writer example of extjs, and I modified the proxy to:
var store = Ext.create('Ext.data.Store', {

// destroy the store if the grid is destroyed
autoDestroy: true,
autoLoad: true,
autoSync: true,
model: 'RigaEu',
proxy: {
type: 'rest',
//url: 'restful/app.php/righeeu',
url: 'EuStats.php/righeeu',
reader: {


type: 'json',
root: 'data'
},

writer: {


type: 'json'

},
buildUrl: function(request) {


var me = this;
var url = me.callOverridden(arguments); // THIS FAILS!
alert('url='+url);
return url+"/7";

}
},

The call to callOverridden() or callParent() fail with the above stack trace.
This looks like a real problem in the Ext.data.proxy.Rest class. If you need to modify the url to add, for example, another fixed parameter, which is the case when you're editing a master-detail page, how would you do you do that?
Futhermore in the documentation there is the sentence:
buildUrl (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Rest-method-buildUrl)( Object (http://docs.sencha.com/ext-js/4-0/#!/api/Object) request )
Specialized version of buildUrl that incorporates the appendId (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Rest-cfg-appendId) and format (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Rest-cfg-format) options into the generated url. Override this to provide further customizations, but remember to call the superclass buildUrl so that additional parameters like the cache buster string are appended


And:
If further customization is needed, simply implement the buildUrl (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Rest-method-buildUrl) method and add your custom generated url onto the Request (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Request) object that is passed to buildUrl. See Rest proxy's implementation (http://docs.sencha.com/ext-js/4-0/source/RestProxy.html#method-Ext.data.proxy.Rest-buildUrl) for an example of how to achieve this.

but the link "Rest proxy's implementation" is broken or is not meant at it.
Anyway I looked into the Rest implementation source code, but I found no relevant information in there apart from seeing that the function buildUrl itself calls "return me.callParent(arguments);".

abstraction.barrier
13 Mar 2012, 9:32 PM
I'm also going to need to make this work very soon. Any new thoughts?

Forza Bo
19 Jul 2012, 1:15 PM
I've run into the same issue. Does anyone have a solution?

Animal
19 Jul 2012, 2:42 PM
Just injecting a method doesn't get callOverridden.

If you just poke your function into the implementation you will have to explicitly call the class's own implementation:



buildUrl: function() {
return Ext.data.proxy.Ajax.prototype.buildUrl.apply(this, arguments) + "&foo";
}

Forza Bo
23 Jul 2012, 8:36 AM
Animal: THANK YOU THANK YOU THANK YOU. :D

I don't completely understand the explanation, but it works.

Cheers,

--Bo

Forza Bo
23 Jul 2012, 9:16 AM
For the benefit of anyone else that runs into this, one slight change to the above code to make it work with the Rest model:




// use Rest prototype, not Ajax:

buildUrl: function() {
return Ext.data.proxy.Rest.prototype.buildUrl.apply(this, arguments) + "&foo"; }