PDA

View Full Version : JsonStore.insert() causes exception



kalan
13 Jan 2011, 12:45 AM
I have an EditorGridPanel with toolbar button to add new records. Everything works fine except one scenario. When I try to insert a record which already exists in database, server sends back:

{"success":false,"message":"already exists","data":{}}

but grid creates a new row marked with red triangle. If after that I try to insert a new record (even if it doesn't exist in database), everything works fine on the server side, but i get an 'uncaught exception' in firebug. It says: 'uncaught exception: Ext.data.DataReader: #realize was called with invalid remote-data. Please see the docs for DataReader#realize and review your DataReader configuration.'

why is that?

EDIT
I have found that:
When I try to insert a new record I use insert method which sends post request with parameter 'data' to server (encode is true, listful is true):

data [{"Name":"123"}]

and it gets:

{"success":true,"data":{"PositionId":"eef1d9f3-9fdf-4b87-9f6c-ef42231f4fed","Name":"123"}}
from server

after that I try to create an item with the same name:
data [{"Name":"123"}]

so I get:
{"success":false,"message":"already exists","data":{}}
from server.

The next time I try to create the right item the store sends array with 2 items
data [{"Name":"1234"},{"Name":"123"}]

but server creates only the first (newest) item and sends back:
{"success":true,"data":{"PositionId":"1ff05c7f-d5fc-41cd-81f3-faabc225b2a6","Name":"1234"}}


So the error may occur because store asks server to create 2 items, but only one is send back. So how to deal with it? is it possible to make store not to send the request for failed item again?