[OPEN] [#619] Error when return StoreResult's Success set to false

Page 1 of 3 123 LastLast
  1. #1

    [OPEN] [#619] Error when return StoreResult's Success set to false

    On the following example, step to page 2. ExampleController.LoadFakeRecords will return StoreResult with Success set to false. This will cause the following error:



    AjaxProxy is trying to call ExampleController.LoadFakeRecords again, without the correct parameters.

    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
    </head>
    <body>
        <ext:ResourceManager runat="server" ScriptMode="Debug" />
        <ext:GridPanel Title="Ext.Net" Width="500" Height="500" runat="server">
            <Store>
                <ext:Store AutoLoad="true" runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="/Example/LoadFakeRecords/" StartParam="start" LimitParam="limit" PageParam="page" SortParam="sort">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader RootProperty="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model IDProperty="ID" runat="server">
                            <Fields>
                                <ext:ModelField Name="ID" />
                                <ext:ModelField Name="Name" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Text="ID" DataIndex="ID" runat="server" />
                    <ext:Column Text="Name" DataIndex="Name" runat="server" />
                </Columns>
            </ColumnModel>
            <BottomBar>
                <ext:PagingToolbar DisplayInfo="true" runat="server" />
            </BottomBar>
        </ext:GridPanel>
    </body>
    </html>
    namespace SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadFakeRecords(int start, int limit, int page, string sort)
            {
                if (page == 2)
                {
                    return new StoreResult
                    {
                        Success = false,
                        Message = "Failed"
                    };
                }
                else
                {
                    List<Person> lst = new List<Person>();
    
                    for (int index = start; index < (page * limit); index++)
                    {
                        lst.Add(new Person
                        {
                            ID = index,
                            Name = "Name" + index
                        });
                    }
    
                    return new StoreResult(lst, (page * limit) + limit);
                }
            }
        }
    
        [Serializable]
        public class Person
        {
            public int ID { get; set; }
    
            public string Name { get; set; }
        }
    }


    it's possible to see that ExampleController.LoadFakeRecords is being called again if its signature is replaced by the following:
    public StoreResult LoadFakeRecords(Nullable<int> start, Nullable<int> limit, Nullable<int> page, string sort)
    Then we get:
    • start: -25
    • limit: 25
    • page: null
    • sort: null
    Attached Thumbnails Click image for larger version. 

Name:	Error001.png 
Views:	34 
Size:	83.5 KB 
ID:	17281  
    Last edited by Daniil; Dec 22, 2014 at 12:24 PM. Reason: [OPEN] [#619]
  2. #2
    Hi Raphael,

    Please try this override.
    Ext.toolbar.Paging.override({
        onLoad : function(){
            var me = this,
                pageData,
                currPage,
                pageCount,
                afterText,
                count,
                isEmpty,
                item;
    
            count = me.store.getCount();
            isEmpty = count === 0;
            if (!isEmpty) {
                pageData = me.getPageData();
                currPage = pageData.currentPage;
                pageCount = pageData.pageCount;
                        
                if (pageCount === 0) {
                    return;
                }
    
                    // Check for invalid current page.
                if (currPage > pageCount) {
                    me.store.loadPage(pageCount);
                    return;
                }
                
                afterText = Ext.String.format(me.afterPageText, isNaN(pageCount) ? 1 : pageCount);
            } else {
                currPage = 0;
                pageCount = 0;
                afterText = Ext.String.format(me.afterPageText, 0);
            }
    
            Ext.suspendLayouts();
            item = me.child('#afterTextItem');
            if (item) {    
                item.setText(afterText);
            }
            item = me.getInputItem();
            if (item) {
                item.setDisabled(isEmpty).setValue(currPage);
            }
            me.setChildDisabled('#first', currPage === 1 || isEmpty);
            me.setChildDisabled('#prev', currPage === 1 || isEmpty);
            me.setChildDisabled('#next', currPage === pageCount  || isEmpty);
            me.setChildDisabled('#last', currPage === pageCount  || isEmpty);
            me.setChildDisabled('#refresh', false);
            me.updateInfo();
            Ext.resumeLayouts(true);
    
            if (!me.calledFromRender) {
                me.fireEvent('change', me, pageData);
            }
        }
    });
  3. #3
    Daniil, the solution provided above overcome the issue but it introduces a new one.

    On the example provided above, with the override provided by you, proceed through the following steps:

    Load the page
    >>> LoadFakeRecords is executed

    Move to page 2
    >>> LoadFakeRecords is executed (Returns success = false)

    Move to page 2 again
    >>> LoadFakeRecords is not executed anymore

    In other workds, applying the override suggested by you, paging becomes died after LoadFakeRecords returns success = false
  4. #4
    I also will try to find a solution for the issue presented above.

    Please keep me posted about any update and be sure that i'll keep you.

    Thanks in advance.
  5. #5
    Please remove the previous Ext.toolbar.Paging override and try this one instead.

    Ext.data.Store.override({
        onProxyLoad: function (operation) {
            var me = this,
                resultSet = operation.getResultSet(),
                records = operation.getRecords(),
                successful = operation.wasSuccessful(),
                session, associatedEntity;
    
            if (me.isDestroyed) {
                return;
            }
    
            if (resultSet && successful) { // Added "&& successful". Probably, a failed load request should not erase the total of a previous successful load request.
                me.totalCount = resultSet.getTotal();
            }
    
            me.loading = false;
            if (successful) {
                session = me.getSession();
                associatedEntity = me.getAssociatedEntity();
                if (session && associatedEntity && !associatedEntity.phantom) {
                    records = me.getRole().validateAssociationRecords(session, associatedEntity, records);
                }
                me.loadRecords(records, operation.getAddRecords() ? {
                    addRecords: true
                } : undefined);
            }
    
            if (me.hasListeners.load) {
                me.fireEvent('load', me, records, successful, operation);
            }
        }
    });
  6. #6
    Thank you Daniil. I will try the solution provided by you and retest. I will keep you posted about any issue that i may find.
  7. #7
    Is there a typo?

                me.loadRecords(records, operation.getAddRecords() ? {
                    addRecords: true
                } : undefined);
    The ": undefined)" bit?
  8. #8
    I would say it is not a typo.

    It is written by ExtJS team:
    http://docs-origin.sencha.com/extjs/...od-onProxyLoad

    Also it appears to be a proper JavaScript code (I mean syntax) and it works as expected.

    Could you, please, clarify why you think that it is a typo?
  9. #9
    For me it is correct although i prefer to use "null" notation
    Last edited by RCN; Dec 22, 2014 at 1:16 PM.
  10. #10
    Apologies - I misread it and didn't notice the use of the ternary operator. It is fine.
Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 8
    Last Post: Dec 18, 2014, 3:00 PM
  2. [CLOSED] Problem on success/failure return from a directMethod
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 30, 2013, 1:04 PM
  3. MessageBus and DirectEvent.Success = false
    By Spamme in forum 2.x Help
    Replies: 1
    Last Post: Aug 13, 2013, 12:24 PM
  4. Replies: 9
    Last Post: Jan 11, 2013, 2:38 PM
  5. Replies: 1
    Last Post: Jun 07, 2010, 7:19 AM

Posting Permissions