ExtJS I don't understand the generated uri's from these proxies - extjs

I just don't understand how ExtJS is building these routes, or how I can stop all of it.
For example, if I'm using a proxy like:
{
type: 'rest',
url: '/user',
noCache: false,
reader: { type: 'json', successProperty: 'success' }
}
I would expect requests like GET /user or POST /user/123 as is the case with restfull apis.
Instead I get stuff like GET /user/root?node=root or GET user?page=1&start=0&limit=25.
Is there a way to get ExtJS to stop adding all these extra params?

The tree store defines a default root id if you don't care of that yourself.
The page and start params are added by the paging toolbar in the grid. Your REST implementation should not be bothered by extra parameters. You can also disable them if you turn paging off.

Related

How do i remove _dc parameter from sencha touch 2 request

In every sencha request there are an extra parameter _dc. Please have took at the following image.
I want to remove this parameter for every request. So, please help me to do that.
Thank You...
_dc - this is "disable cache". You can disable this noCache parameter in proxy in your store\model. Example:
Ext.define('your model name', {
extend: 'Ext.data.Model',
fields: [...],
proxy: {
url: 'getcandidateblock',
noCache: false
}
})
But it's bad idea for ALL get requests to server.
Use 'noCache' config in your store's proxy
To disable the '_dc' query param, set this to false.
From Sencha Doc,
noCache - Disable caching by adding a unique parameter name to the request. Set to false to allow caching. Defaults to true.

Sencha and Java Servlet sync()

I am adapting a tutorial to change from localstorage to use a java servlet but i am having some problems. I am trying to update the changes a user makes by calling sync() but i am getting these errors.
[WARN][Ext.data.Operation#process] Unable to match the record that came back from the server.
I tried seeing if the updated values where being send to the servlet
String name = request.getParameter("name");
is null. How do I send the updated values back the server and read them? I tried looking for a sencha touch + servlets tutorial but can't find anything
this is my sync code
var showsStore = Ext.getStore("Shows");
if (null == showsStore.findRecord('name', currentShow.data.name)) {
showsStore.add(currentShow);
}
showsStore.sync();
The expected return for a store sync is an array of JSON records, or nothing.
Add this to your data store
writer: {
type: 'json',
rootProperty: 'data',
encode: true,
writeAllFields: true
},

Proxy JsonP and callbackkey

im near to finish my app and when try to put in onlin server i find some problems...
My proxy don't work with ajax issue, i need to put jsonp and configure my drupal to use JsonP.
Before:
proxy: {
type: 'ajax',
url: 'http://mydomain/json-art',
reader: {
type: 'json',
rootProperty: 'nodes'
},
}
After:
proxy: {
type: 'jsonp',
url: 'http://mydomain/json-art',
callbackKey: 'callback',
reader: {
type: 'json',
rootProperty: 'nodes'
},
}
Then in Drupal 7 put... JsonP prefix: Ext.data.JsonP.callback1
And.. all works fine.
But.. I have 4 Stores in my app, and try to reply this configuration in my other stores. And only works for the first one. I try to change the callback1 to callback2, callback3, etc.. but always have the same error:
Object [object Object] has no method 'callback4'
I don't know whats the correct way to use callbackKey in my app, pls help me!!!!
Thx
What I figure from "the internet", the drupal JSONP Prefix is either a set string to use, or the name of the url variable to check. If you set the JSON Prefix to "callback", it should work fine. This is because the the Sencha JsonP call will auto-append a url parameter named "callback", which contains the name of the function to call (typically Ext.data.JsonP.callback#number#.
Note that your solution is not even right for one datastore. Not entirely sure why you get the behaviour you get, but each JsonP call should have a different callback functionname.
There is no need to specify a callback (if it's even possible, not sure) in a proxy. Just get rid of the 'callbackKey' param and it should work. Sencha automatically places a callback parameter when using jsonp.

Writing store updates back to server

I have read the Sencha tutorials, API, and forums for awhile but am hitting a brick wall. I have a mySQL/PHP backend that is storing a web application's data. I have the following Sench/ExtJS construct:
App.stores.user = new Ext.data.Store({
model: 'User',
proxy: new Ext.data.AjaxProxy({
url: 'app/stores/scripts/connect.php',
extraParams: {
method:'user',
user_id: 3
},
reader: {
type:'json',
root:'root'
}
}),
autoLoad:true
});
Data is loaded into the store fine, but I have a form that directly updates a User instance.
App.controllers.account = new Ext.Controller({
save: function (options) {
options.user.set(options.data);
options.user.save(); // Generates error: Uncaught Error: You are using a ServerProxy but have not supplied it with a url.
}
});
How can I successfully implement/hook the functions to write the dirty records back to the server? How is the request prepared and passed?
Thank you.
Uptil Ext Js 3.3.1 the store needs to be configured with a writer when performing CRUD operations. It isn't needed for read only. That's why your store is loaded but you're getting an error during write operations. In your case you'll have to specify a JsonWriter. Also, if you're not using the store in a restful manner, then you'll also need to specify a HttpProxy object to tell the store at which url to publish the create/update/delete on the store.
Check the docs for Ext 4. I should be something similar here too.

Removing _dc parameter in Ext

Using Ext, default Ext.Ajax add to GET-request _dc parameter. For example
GET /ConnViewProcessing/?_dc=1263286227619
How to remove this parameter?
PS: it's necessary to manually cache response to ETag and If-None-Match.
Set disableCaching option to false:
Ext.Ajax.disableCaching = false;
Using Ext JS 4.1, and after adding the following code to app.js, the _dc parameter disappears:
// Disable _dc parameter
Ext.Loader.setConfig({
disableCaching: false
});
// My App
Ext.application({
The proper way to accomplish that with Sencha Cmd 6.x is to set a (global) switch in app.json (because all of those hacks and overrides might interfere unnecessarily with the functionality):
"loader": {
"cache": true
},
Then run sencha app refresh, in order to update the application's bootstrap.json.
Alternatively, one can configure Ext.Loader (at run-time):
Ext.Loader.setConfig({disableCaching: false});
When scrolling upwards and reading the actual question, concerning Ext.Ajax (per request):
Ext.Ajax.request({url: '/ConnViewProcessing', disableCaching: false});
The result: no more _dc parameters on scripted requests.
#see Sencha Cmd 6.x - The Microloader.
Note that the use of Ext.Loader has changed in ExtJS 5.
In ExtJS 5, caching can be disabled:
temporarily by adding "?cache" to the end of the URL
by setting a cookie called 'ext-cache' with the value of 1
or by editing the file .sencha/app/Boot.js and setting the '_config.disableCaching' property to be true (overwriting the dynamic lookup).
I am using ExtJS 4.2, but this should work for Ext JS 4.1 and on. In the proxy there is a property called noCache you should set this to false.
Ext4.define('Server',{
extend: 'Ext4.data.Model',
fields: [
{name: 'id'},
{name: 'key'},
{name: 'value'}
],
proxy: {
type: 'rest',
url : 'yaddayaddayadda',
noCache: false,
reader : {
type: 'json'
}
}
});
The reason my code says Ext4. is because I am using the sandbox mode as I move old Ext JS 3x code into 4.2
This should work with extjs 4.0.7:
Ext.Loader.config.disableCaching = false;
Setting the flag disableCaching to false (double negation - yay!) on the Ext.data.Connection should do the trick.
For more, look at the disableCaching-documentation.
(Please note that quite a few classes in Ext seem to have the option available, so you might have to muck around a bit.)
For those that want to set "disableCaching: false" in Sencha Architect 3+, here is how..:
In the project inspector window, select the top node,
"Application"
Then in the "Config" window below that where you
set the object properties, etc, select "Loader Config".. in my case
I had to click the "+" to the right of this as I hadn't set any
items yet. This will create a new "LoaderXX" object in the "Project
Inspector" window above; Loader25 in my case.
Now either select the new object in the
"Project Inspector" window, or click on the right arrow beside the
new "LoaderXX" (Loader25 in my case). This will take you to the
properties for the object.
Untick the "disableCaching" item.
Save the project and refresh the browser window, and enjoy persistent breakpoints, etc, etc in Chrome.
The only way I was able to disable _dc in ExtJS 4.2.x globally on my project:
Ext.define('Ext.data.Connection', {override:'Ext.data.Connection', disableCaching:false });
Ext.define('Ext.data.proxy.Server', {override:'Ext.data.proxy.Server', noCache:false });
Ext.define('Ext.data.JsonP', {override:'Ext.data.JsonP', disableCaching:false });
This is ugly, but any other ideas?
This is how I did this:
Ext.Ajax.request({
url: url,
disableCaching:false
});
I decided that I wanted the cache to be destroyed client side, but server side I was using my own caching mechanism (PHP's APC).
I left the _dc in the Ext ajax request, but then removed it from the REQUEST_URI, and then use the REQUEST_URI as the basis for the cache key
I found this useful: Regular expression to remove one parameter from query string
If you develop under Sencha CMD you can do like this
http://localhost:1841/?disableCacheBuster
or just
http://localhost:1841/?cache
For all who are looking for a way to disable it in a newer version:
proxy: {
type: 'ajax',
noCace: false
}
I use Ext.NET on top of Ext.JS. It adds some more voodoo to Ext.js...
I tried to get rid of the dc= parameter, but all mentioned configurations did not work. So, this is my uber-effective, uber-dirty solution:
Ext.Date.now = function () { return ""; }
As far as I can see, Ext.Date.now() is only used for the caching logic. So it should be relativity save.

Resources