Results 1 to 9 of 9

Thread: Store proxy exception fired though successful

  1. #1
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Question Store proxy exception fired though successful

    I could not find this discussed in the forum. If so, let me know.
    I have an Ext.data.Store with proxy defined as:
    Code:
    proxy:
    new Ext.data.HttpProxy({
    api: {
    load: '../config/op.aspx?o=0',
    create: '../config/op.aspx?o=1',
    save: '../config/op.aspx?o=2',
    destroy: '../config/op.aspx?o=3'
    }
    })

    These operations function successfully. When I added to perform post processing on the create, I learned that while { success:true } was returned, the createexception event was fired and not the create event.

    I'm obviously misunderstanding something. Any insight would be appreciated.
    Last edited by VinylFox; 7 May 2009 at 1:55 PM. Reason: added CODE tags

  2. #2
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    Whats your entire response look like?

  3. #3
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Default

    I have tried both the simple:
    { success:true }
    or, where I am also returning the newly inserted record from the server database:
    { success:true, rows: [{'id':'3000015','LocNo':'A222','ServiceNo':'02.45','AcctNo':'001-400-2','LocName'
    :'2a','LocDescription':'sdfsdafdsfas fsdasafsfsfa'}]}
    I can format however is required. Below is the Store definition. I appreciate any insight you can provide. This is from an web app I started building with extJS 2.2 in December.

    Code:
    page.locStore = new Ext.data.Store({
              fields: page.locFields
            , baseParams: { 'g': '0' }
            , id: 'id'
            , url: '../config/op.aspx?o=0', 
            , autoLoad: true
            , reader: new Ext.data.JsonReader({
                root: 'rows',
                id: 'id'
            }, [
                'id'
                , 'LocNo'
                , 'ServiceNo'
                , 'AcctNo'
                , 'LocName'
                , 'LocDescription'
                ])
    
    , proxy: new Ext.data.HttpProxy({ api: { load: '../config/op.aspx?o=0', create: '../config/op.aspx?o=1', save: '../config/op.aspx?o=2', destroy: '../config/op.aspx?o=3' } }) , batchSave: false , writer: new Ext.data.JsonWriter({ returnJson: true, writeAllFields: true }) , listeners: { create: function(store, result, ex) { // response from server when a new loc was created //alert("create returned"); -- NEVER OCCURS NewLocServerResponse(store, result, ex); } , createexception: function(directProxy, record, ex) { //alert("createexception: " + ex.toString()); // ALWAYS OCCURS } , save: function(store, record, ex) { alert("save"); } , saveexception: function(directProxy, record, ex) { alert("saveexception: " + ex.toString()); } , destroy: function(store, record, ex) { alert("destroy"); } , destroyexception: function(directProxy, record, ex) { alert("destroyexception: " + ex.toString()); } , load: function(st, recs, opt) { alert("afterload of groupDefStore count: " + recs.length); } , loadexception: function() { alert("loadexception event in groupDefStore"); } } });
    Code:
    
    
    Last edited by VinylFox; 7 May 2009 at 1:56 PM. Reason: added CODE tags

  4. #4
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Default

    I appreciate your quick reply to my initial posting.

    From Firebug I see that the server responds with the data as in my previous posts and a 200 OK. Perhaps there is more that I must do to let extJS know that the response is in JSON format?



    BTW - I have your book here within reach. Nicely done!

  5. #5
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    Did you add the 'create' event to your component?

    Ill ping Chris, and see if he can chime in on this.

    Glad you enjoyed the book

  6. #6
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Default

    I don't understand. So, I'd have to then say No.

    In the code I have a javascript object named page that contains the Store in a property named locStore. This Store has listeners for the create and createexception events. The intent was that upon successfully creating a new record in the Store, the Store would invoke the proxy: create: '../config/op.aspx?o=1', passing the contents of the new record to the server which in turn would update the database. All this works fine. When the server responds with the success message I had hoped the Store's create event handler would fire. The event handler would allow further processing on the client with the new record, knowing that it has been successfully saved in the database. The issue is that the Store's createexception event is firing instead of the create event. It seems that the Store/Proxy/... is interpreting my server response as a failure instead of as a success.

  7. #7
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Default

    If the component you were referring to is the Ext.data.Store, then yes. It has listeners for both create and createexception.

  8. #8
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381

    Default

    In SVN, I refactored all the events "create", "destroy", "save" events into simply "write". I found it too complex to manage all these different events.

    Before I refactored these events, I noticed a bug where Store was firing "createexception" on "create" event, I think (or vice-versa). Perhaps that's what you're seeing.

    So it's now "write", "beforewrite" and "writeexception". Notice the 2nd param to all these events is {String} action. You can make a switch in your handler.

    Code:
    /**
             * @event beforewrite
             * @param {Store} store
             * @param {String} action
             * @param {Record/Array[Record]} rs
             * @param {Object} options HTTP request object.  edit <tt>options.params</tt> to add Http parameters to request.
             */
            'beforewrite',
            /**
             * @event write
             * fires when server returns 200 after Ext.data.CREATE, UPDATE and DESTROY.  Check the res['successProperty'] of the Response
             * parameter for action's success/fail.
             *  in favor of this one "write" event.
             * @param {Extd.data.Store} store
             * @param {String} action [Ext.data.Api.CREATE|UPDATE|DESTROY]
             * @param {Object} result The "data" picked-out out of the response for convenience.
             * @param {Ext.Direct.Transaction} res
             * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
             */
            'write',
            /**
             * @event writeexception
             * Fires when an exception occurred while writing remote-data.
             * @param {Extd.data.Store} store
             * @param {String} action [Ext.data.Api.CREATE|UPDATE|DESTROY]
             * @param {Object} result null
             * @param {Ext.Direct.Transaction} res
             * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
             */
            'writeexception'
    Another thing, in your DataReader config:
    Code:
    reader: new Ext.data.JsonReader({
                root: 'rows',
                id: 'id' // <-- The param is called idProperty, not id
            }
    idProperty default is "id", so your code works anyway.
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  9. #9
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Illinois, USA
    Posts
    9

    Default

    Chris, thanks so much for your quick response.
    The RC1 code is calling createexception in all cases whether the server response is successful or not. I will evaluate the SVN code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •