Sencha and Java Servlet sync() - extjs

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
},

Related

ExtJS 4 DirectProxy simultaneously store load

I have 2 stores with different models but same direct proxy configuration. When i load these 2 stores (i call store.load() for both stores at the same time) ext is sending only one request (containing both loads) and the second store is not populated with data. I tried setting batchActions to false with no success. I am using ext direct spring on server side.
Proxy configuration:
proxy: {
type: 'direct',
batchActions:false,
directFn:doctorDirectController.getAll,
reader:{
type:'json',
root:'records'
}
}
When i set timeout for 1 sec everything works fine:
this.doctorStore1.load();
var me = this;
setTimeout(function() {
me.doctorStore2.load();
}, 1000);
So the 2 questions:
How to force directproxy not to batch getAll requests
Why second store is not being populated with data? The request and response contains tids that match up.
It turned out to be problem with Spring. To handle cycling references between entities (which caused problems during jackson serialization) i used following annotation
#JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="#doctorId")
When simultaneous 2 store loads occured they were serialized in one batch and send back in one response. The above annotation was removing all the duplicates during json serialization causing second store not to be populated with data.

Extjs 5 model id' is not concatenating with REST URL - working in Extjs 4.2

Sorry!! may be i was not clear, I modified the question, Actual problem is that 'I am setting the id on the model and it is working fine in Extjs 4.2' and i am able to print the id from within the model object on console but this 'id' is not concatenating with REST URL like 'rest/update/user/123'
I really need your help.
In Extjs 4.2, I am posting a form data to a rest url (update using proxy in model class ), it was working fine and send the request to the server as:
rest/update/user/123
but in Extjs 5 same request is being interpreted as:
rest/update/user //without he id of the object
it does not send the id of the object in the REST CALL URL (id has value inside the object)
//here is proxy in the model
proxy: {
type: 'rest',
url: ' rest/update/user'
}
//controller
var model = Ext.create('MyApp.model.User');
model.set('id', "123"); // please see here, i am adding the Id so it is not phantom
model.set('userName', "john");
model.save();
Please help!!
Thanks.
Model seems to be phantom (new). Call model.commit() before save.

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

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.

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.

Resources