Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • After filtering on ListGrid all others operations on Records are ignored

    Hi Isomorphic,

    we are facing a problem with our implementation of UI did by smartgwt component.
    Here is a UI designed: it is encapsulate in wizard step

    Click image for larger version

Name:	UI_design_listgrid_with_filtering.jpg
Views:	5
Size:	52.6 KB
ID:	256527

    Here is a Grid java code:
    Code:
    package com.xxxxxxxx.gwt.wep.client.bcm.create.steps.supportedServices;
    
    import java.util.Map;
    
    import com.google.gwt.i18n.client.ConstantsWithLookup;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.ResultSet;
    import com.smartgwt.client.types.FetchMode;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.ValuesManager;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.xxxxxxxx.gwt.wep.client.bcm.brand.BcmBrandI18n;
    import com.xxxxxxxx.gwt.wep.client.bcm.datasources.BcmSupportedServicesDataSource;
    import com.xxxxxxxx.gwt.wep.client.common.buttons.ActionButtons;
    import com.xxxxxxxx.gwt.wep.client.common.buttons.WepButton;
    import com.xxxxxxxx.gwt.wep.client.common.i18n.MessagesFactory;
    import com.xxxxxxxx.gwt.wep.client.common.layout.DataViewer;
    import com.xxxxxxxx.gwt.wep.client.common.listgrid.fields.AdvancedListGridField;
    import com.xxxxxxxx.gwt.wep.client.common.messages.GeneralMessages;
    import com.xxxxxxxx.gwt.wep.client.common.styleformatters.Colors;
    import com.xxxxxxxx.gwt.wep.client.fields.FieldUtils;
    import com.xxxxxxxx.gwt.wep.client.issuing.common.FeedbackWindowHelper;
    import com.xxxxxxxx.gwt.wep.client.issuing.common.listgrid.IssuingWepListGridWithActions;
    import com.xxxxxxxx.gwt.wep.shared.bcm.brand.BcmBrandFields;
    import com.xxxxxxxx.gwt.wep.shared.issuing.IssuingGeneralFields;
    
    public class BcmWizardSupportedServicesGrid extends IssuingWepListGridWithActions implements DataViewer {
    
        private static final DataSource dataSource;
        private static final BcmBrandI18n i18n;
        private String parentBrandName = "";
    
        private ValuesManager wizardValuesManager;
    
        static {
            i18n = MessagesFactory.getMessages(BcmBrandI18n.class);
            dataSource = BcmSupportedServicesDataSource.getInstance();
        }
    
        public BcmWizardSupportedServicesGrid(String locatorId, ValuesManager wizardValuesManager) {
            super(locatorId, "supported_services", dataSource, i18n);
    
            this.wizardValuesManager = wizardValuesManager;
    
            setAutoFitData(null);
            createAddButton();
        }
    
        private void createAddButton() {
            WepButton addButton = new WepButton(extendLocatorId("addButton"), MessagesFactory.getMessages(GeneralMessages.class).addLabel(),
                    true);
            addButton.select();
    
            addButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new AddSupportedServiceWindow(extendLocatorId("addSupportedServiceWindow"), BcmWizardSupportedServicesGrid.this).show();
                }
    
            });
    
            HLayout buttonsLayout = new HLayout();
            buttonsLayout.setLayoutBottomMargin(10);
            buttonsLayout.addMember(addButton);
            buttonsLayout.setBackgroundColor(Colors.WHITE);
            addTopLayoutMember(buttonsLayout, 0);
        }
    
        @Override
        protected void onPreInitialize() {
            super.onPreInitialize();
    
            setSaveLocally(true);
        }
    
        @Override
        protected void onPostInitialize() {
            super.onPostInitialize();
            setBackgroundColor(Colors.LIGHT_GRAY);
            setMargin(15);
    
            setCanEdit(true);
            setEditEvent(ListGridEditEvent.CLICK);
            setEditByCell(true);
            setShowRecordComponents(true);
            setShowRecordComponentsByCell(true);
    
            setShowFilterEditor(true);
    
            sort(BcmBrandFields.service.name(), SortDirection.ASCENDING);
        }
    
        @Override
        protected ResultSet createResultSetProperties() {
            ResultSet resultSet = super.createResultSetProperties();
            resultSet.setFetchMode(FetchMode.BASIC);
            resultSet.setUseClientFiltering(true);
            return resultSet;
        }
    
        @Override
        protected ConstantsWithLookup getSpecificI18n() {
            return i18n;
        }
    
        @Override
        public DataSource getDataSource() {
            return null;
        }
    
        @Override
        public Canvas getCanvas() {
            return this;
        }
    
        public void fetchData(Map values) {
            final String wizardParentBrandName = (String) values.get(BcmBrandFields.parentName.name());
            if (!parentBrandName.equals(wizardParentBrandName)) {
                DSRequest dsRequest = new DSRequest();
                dsRequest.setWillHandleError(true);
                dataSource.fetchData(new Criteria(BcmBrandFields.name.name(), wizardParentBrandName), new DSCallback() {
    
                    @Override
                    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                        if (dsResponse.getStatus() == DSResponse.STATUS_SUCCESS) {
                            BcmWizardSupportedServicesGrid.this.setData(dsResponse.getData());
    
                            parentBrandName = wizardParentBrandName;
    
                            setFilterLocalData(true);
                        } else {
                            FeedbackWindowHelper.getErrorWindow(i18n, "fetchSupportedServicesError", dsResponse).show();
                        }
                    }
                }, dsRequest);
            }
        }
    
        @Override
        public void setDataForViewer(Record... data) {
        }
    
        @Override
        protected boolean addActionsColumn() {
            return true;
        }
    
        @Override
        protected ListGridField[] createAllListGridFieldsExceptActions() {
            AdvancedListGridField enabled = FieldUtils.getSimpleListGridField(BcmBrandFields.isEnabled, 150, false);
            enabled.setCanEdit(true);
    
            AdvancedListGridField allowedOnFirst = FieldUtils.getSimpleListGridField(BcmBrandFields.allowedOnFirst, 150, false);
            allowedOnFirst.setCanEdit(true);
    
            AdvancedListGridField service = FieldUtils.getSimpleListGridField(BcmBrandFields.service, 450, false);
            service.setCanEdit(false);
            service.setSortByDisplayField(true);
            service.setFilterEditorProperties(new TextItem());
    
            return new ListGridField[] { service, allowedOnFirst, enabled };
        }
    
        @Override
        protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
            String fieldName = getFieldName(colNum);
            if (IssuingGeneralFields.actionsColumn.name().equals(fieldName)) {
                ActionButtons recordCanvas = new ActionButtons(15);
    
                WepButton removeButton = new WepButton(extendLocatorId("removeServiceButton"), i18n.remove_label(), true);
                removeButton.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        int poz = BcmWizardSupportedServicesGrid.this.getRowNum(record);
                        BcmWizardSupportedServicesGrid.this.getRecordList().removeAt(poz);
                    }
                });
                recordCanvas.addMember(removeButton);
                return recordCanvas;
            } else {
                return super.createRecordComponent(record, colNum);
            }
        }
    }
    Issue: First, we are fetching data from our data source. Data are set by BcmWizardSupportedServicesGrid.this.setData(dsResponse.getData()); method ... all data are set up and represented by com.smartgwt.client.data.RecordList object ... we are able to remove or add any new record into grid .. Then, we want to filter and do any update only locally so setFilterLocalData(true);

    When, we are filtering:
    Click image for larger version

Name:	UI_filtering.jpg
Views:	2
Size:	38.1 KB
ID:	256529

    records are stored in com.smartgwt.client.data.ResultSet , removing by Remove button and adding by Add button are ignored and there is an exception thrown:

    Code:
    15:02:12.781 [ERROR] [portal] 15:02:12.753:MUP2:WARN:Log:ResultSets are readonly. This operation (removeAt) will be ignored.
    
    com.smartgwt.client.core.JsObject$SGWT_WARN: 15:02:12.753:MUP2:WARN:Log:ResultSets are readonly. This operation (removeAt) will be ignored.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.smartgwt.client.data.RecordList.removeAt(RecordList.java)
        at com.xxxxxxxx.gwt.wep.client.bcm.create.steps.supportedServices.BcmWizardSupportedServicesGrid$3.onClick(BcmWizardSupportedServicesGrid.java:187)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:111)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
        at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
        at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
        at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
        at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
        at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
        at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:299)
        at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:296)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:551)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368)
        at java.lang.Thread.run(Thread.java:745)
    Code:
    15:47:30.210 [ERROR] [portal] 15:47:30.188:MUP8:WARN:Log:ResultSets are readonly. This operation (addAt) will be ignored.
    
    com.smartgwt.client.core.JsObject$SGWT_WARN: 15:47:30.188:MUP8:WARN:Log:ResultSets are readonly. This operation (addAt) will be ignored.
        at sun.reflect.GeneratedConstructorAccessor33.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:315)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
        at com.smartgwt.client.data.RecordList.add(RecordList.java)
        at com.xxxxxxxx.gwt.wep.client.bcm.create.steps.supportedServices.AddSupportedServiceWindow$3.onClick(AddSupportedServiceWindow.java:117)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:111)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
        at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
        at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
        at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
        at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
        at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
        at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:299)
        at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:296)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:551)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368)
        at java.lang.Thread.run(Thread.java:745)
    After removing "load" text from filter text box and pressing ENTER, all records are shown again, but they are stored in com.smartgwt.client.data.ResultSet instead of com.smartgwt.client.data.RecordList and here we thing that there is a bug, records should be stored again in RecordList when there is no filtering applied to . Isn't it?

    QUESTION: How we can use filtering and add new record or remove record from filtered group of records? Is there any way how to do ResultSet editable? Any set method on grid?
    We want to add/ remove record in grid with or without filtering.


    Required info:
    1. SmartClient Version: v10.0p_2018-06-25/PowerEdition Deployment (built 2018-06-25) ... SmartGWT: 5.0-p20180625
    2. for developing Firefox: 26.0 and directly to server: Chrome - Version 71.0.3578.98 (Official Build) (64-bit)
    Attached Files

  • #2
    In general, a ResultSet is a partial cache of a remote dataset, so it would be invalid to just remove records as this would de-sync client and server record indices.

    You can use DataSource.updateCaches() to update data contained in a ResultSet, but note that this would affect any other components that have a cache of the same data, causing them to remove the same record.

    If what you want instead is to take a subset of a DataSource's data and manipulate it client-side, DataSource.getClientOnlyDataSource() is the quickest way to do that. Here again, do any updates via DataSource.updateCaches(), except now you will affect only the temporarily client-only DataSource you have set up.

    Comment


    • #3
      HI,

      your solution for us is just partly ... Client only DS is OK ... but when we updated records and then filtered records all changes where removed because each filter ran fetch and changes were removed(i mean changed records in grid) ... so updateCaches() works only those records which are visible ..Instead of this we need to call same operation as normally, but our DS is client only so no call is sent to backend/server side ..all data(added/removed/updated) are updated in time and we have still up to date data ..

      Thanks.

      Comment


      • #4
        We provided solutions to both possible cases of the behavior you might want. Please re-read.

        Comment

        Working...
        X