[FIXED] [#1276] [4.2.0] Error in StoreCustomLogic example

  1. #1

    [FIXED] [#1276] [4.2.0] Error in StoreCustomLogic example

    Hi,
    I'm trying to base some code on the example https://examples4.ext.net/#/GridPane...reCustomLogic/
    but the example gives an error when performing 2 different actions.

    For example, if you update a record and create a new record and then click on Save, there is an error during the sync().
    It works if you only have one type of action (eg: Updates only or Creates only).

    Any help will be appreciated as I'm experiencing the same issue in my code.
    Last edited by Daniil; May 11, 2016 at 2:06 PM. Reason: [FIXED] [#1276] [4.2.0]
  2. #2
    Hello,

    Can you detail your steps? I experimented changing an entry and then adding another. No error saving.

    My steps were:
    1. Edit company 'Escargots Noveaux' (renamed to 'Escargots Noveauxus').
    2. Create a new entry. Fill every field except fax, in order:
    Record data used:
    - Record for tests 0001
    - Test is 001
    - Testament
    - Street Testers
    - Testborough
    - Testoland
    - 12345
    - Testinent
    - (123) 456-7890
    - (blank)

    No error.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi fabricio, thanks for your response.

    I followed similar steps and for me an error occurs during the save. The same steps as you outlined:
    1. Edit company 'Escargots Noveaux' (renamed to 'Escargots Noveaux123').
    2. Create a new entry. Fill every field except fax, in order:
    Record data used:
    - Record for tests 0002
    - Test
    - Test
    - Test
    - Test
    - Test
    - 12345
    - Test
    - (123) 456-7890
    - (blank)
    3. Click on the Save button

    If the above steps are followed with Firebug or developer tools open, the following error appears:

    a is null - ext-all.js (Line 1, col 625850)

    It looks like it is trying to use a reader on the proxy to read the response data, but me.getReader() is returning null. This happens only on the second action.

    Thank you for any help you can provide.
  4. #4
    Have you been testing this only on Firefox? Can you check if with IE or Chrome it works for you? Maybe it is a firefox-specific issue? I've just installed firefox here and it works as well.

    EDIT: okay, I got the issue you are talking about. It does not visually or functionally glitch the view (as far as I could notice), but just the error happens if I am catching unhandled exceptions.
    Last edited by fabricio.murta; Jan 27, 2016 at 3:31 PM.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Fabricio,
    Thanks again for looking into this issue. The problem is that when multiple operations are being performed, only the first one will be processed but the second and third (if any) will not. For example, assuming the process order is create,update,destroy and all operations return success. When the user makes changes to the records in the grid which cause all 3 operations to be required:


    • The first call to store.sync() will cause the new records to be sent to the code-behind, then the unhandled exception will occur which prevents the update and delete operations from being performed.
    • Calling store.sync() again will cause the updated records to be sent and then the exception will occur.
    • Calling store.sync() a third time will cause the deleted records to be sent.


    The exception seems to be caused by the way the temporary proxy is being destroyed. The temporary proxy is needed until all 3 (potential) operations are completed, but it is destroyed after the first operation when endprocessresponse happens. I've tried the following fix which seems to correct the problem (the only change is the if statement in the endprocessresponse handler):

    Ext.data.AbstractStore.override({
    
        createTempProxy: function (callback, proxyConfig, sync) {
            var oldProxy = this.proxy,
                proxyId = Ext.id(),
                proxy = this.serverProxy ? Ext.createByAlias('proxy.' + this.serverProxy.type, Ext.apply({
                    model: this.model,
                    reader: {
                        type: oldProxy && oldProxy.reader && oldProxy.reader.type ? oldProxy.reader.type : "json",
                        rootProperty: oldProxy && oldProxy.reader ? "data." + oldProxy.reader.getRootProperty() : "data"
                    },
                    writer: oldProxy.writer
                }, proxyConfig || {}, this.serverProxy)) : Ext.createByAlias('proxy.page', Ext.applyIf({
                    type: 'page',
                    model: this.model,
                    reader: {
                        type: oldProxy && oldProxy.reader && oldProxy.reader.type ? oldProxy.reader.type : "json",
                        rootProperty: oldProxy && oldProxy.reader ? "data." + oldProxy.reader.getRootProperty() : "data"
                    },
                    writer: oldProxy.writer
                }, proxyConfig || {})),
                scope;
    
            this.proxy = proxy;
            this[proxyId] = proxy;
            this._oldProxy = oldProxy;
    
            this.proxy.on("exception", this.onProxyException, this);
            this.proxy.on("beforerequest", this.buildRequestParams, this);
    
            this.proxy.on("beforerequest", function () {
                this.proxy = oldProxy;
            }, this, { single: true });
    
            scope = {
                proxyId: proxyId,
                callback: callback,
                proxy: this.proxy,
                oldProxy: oldProxy,
                store: this
            };
    
            if (callback) {
                if (sync) {
                    this.proxy.onBatchComplete = Ext.Function.createInterceptor(
                        this.proxy.onBatchComplete,
                        function (batchOptions, batch) {
                            this.callback.call(this, null, !batch.hasException);
                        },
                        scope
                    );
                }
                else {
                    this.proxy.on(
                        "afterrequest",
                        function (proxy, request, success) {
                            this.callback.call(this, request, success);
                        },
                        scope);
                }
            }
    
            this.proxy.on(
                "endprocessresponse",
                function (proxy, response, operation) {
                    if (!this.store.isSyncing) {                        // add this check to be sure the operations are all complete
                        this.proxy.destroy();
                        this.proxy.clearListeners();
                        delete this.store[this.proxyId];
                        delete this.store._oldProxy;
                    }
                },
                scope
            );
        }
    });
    I've tested this with version 3.3 and the 4.0 examples and it seems to solve the problem.
  6. #6
    Hello @chrisuae!

    Impressive investigation and fix! Sorry for taking so long to reply to your contributive reply!

    Your override looks fine and functional. We'll create an issue to further investigate it. If by any chance there's a better way to do it, or if Sencha is aware of the problem and fixing on their own, and also if that does not imply problems on other situations or use cases.

    Thank you very much for the contribution and feedback!
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Hello again! We've just created issue #1273 to track and fix (or clarify) this issue!..

    I could find an interesting sencha thread where it suggests that maybe the sync() call could have been used in a not-so-good way in our examples, although it probably have been okay for older Ext.NET (& ExtJS) versions, when it was written. Check out the issue linked above for more details!
    Last edited by Daniil; Mar 10, 2016 at 5:04 PM.
    Fabrício Murta
    Developer & Support Expert
  8. #8
    Hello!

    It has been fixed in both v3 and v4 sources.

    As for v4, we, unfortunately, could not make the fix included into recently released 4.1.0, but it will be included into the next release which is likely going to be named as 4.2.0.

    As for v3, it is not a certain thing that any new v3 release will happen, but if it is, the fix will be included.

    @chrisuae, thank you for the great report and proposed fix!

Similar Threads

  1. Version 1.0 Preview
    By geoffrey.mcgill in forum Open Discussions
    Replies: 66
    Last Post: Nov 03, 2010, 9:12 PM
  2. Coolite don't run en IE9 preview
    By gpcontreras in forum 1.x Help
    Replies: 1
    Last Post: Aug 06, 2010, 3:51 PM
  3. Replies: 1
    Last Post: Apr 24, 2010, 12:03 AM
  4. 1.0 Preview
    By roastedamoeba in forum Open Discussions
    Replies: 5
    Last Post: Jan 24, 2010, 1:21 AM
  5. version 8 example preview
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: May 10, 2009, 7:00 PM

Tags for this Thread

Posting Permissions