Announcement

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

    ListGrid.setViewState not working?

    ListGrid.setViewState(viewStateString) is not working.

    From the demo
    http://www.smartclient.com/smartgwt/showcase/#grid_appearance_preferences

    1. Adjust the Flag column to make it really wide.
    2. Save Preference, give it a preference name "WideFlagColumn"
    3. Change the Preference SelectItem back to "Default"
    4. Expected behavior is the list grid gets reset, but the Flag column stays wide.

    I am trying to incorporate this into our application, but also experiencing this issue where setViewState appears to have no effect.

    #2
    This sample appears to be working fine. Since you didn't mention it, you do realize that you need to press the "Restore State" button after selecting one of the saved preferences?

    Comment


      #3
      Didn't noticed the button down there.
      The button down there applies to selected preference from the bottom grid.

      Two follow up questions.

      1. From looking at the source code, looks like by selecting the Preference SelectItem should restore the state as well, but it's not happening. I'm less concern about this one as at least I know the restore is working from the Restore State button.

      2. Does this setViewState needs to be called after render/draw?

      Comment


        #4
        Something is definitely wrong with the sample code for the SelectItem, we'll fix that. It's not an issue with the setViewState() API or with the framework in general as far as we can see.

        You don't need to wait for draw to call setViewState(), but you do need to do it after you've provided the DataSource and fields if any.

        Comment


          #5
          Hello Isomorphic,

          I might be seeing a similar problem:

          My order of calls is:
          Code:
          setShowFilterEditor(true);
          setDataSource(myDS);
          setAutoFetchData(false);
          setGroupStartOpen(GroupStartOpen.ALL);
          setFetchOperation("fetchOp");
          setGroupByMaxRecords(456);
          setShowRecordComponents(true);
          setShowRecordComponentsByCell(true);
          setHilites(new Hilite[] { ... });
          setFields(...);
          setFieldState(...persisted old string...);
          setSortState(...persisted old string...);
          setGroupState(...persisted old string...); [B]//Exception here![/B]
          fetchData(...);
          DevMode FF26 Stack Trace:
          Code:
          22:48:54.638 [ERROR] [lms] Uncaught exception escaped
          
          com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) @com.smartgwt.client.widgets.BaseWidget::setProperty(Ljava/lang/String;Ljava/lang/String;)([string: 'groupState', string: '([{fieldName:"STATUS_SHORTNAME",groupingMode:null,groupGranularity:null,groupPrecision:null}])']): this.completeFields is undefined
              at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
              at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
              at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
              at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
              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:347)
              at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
              at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
              at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
              at java.lang.Thread.run(Unknown Source)
          Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) @com.smartgwt.client.widgets.BaseWidget::setProperty(Ljava/lang/String;Ljava/lang/String;)([string: 'groupState', string: '([{fieldName:"STATUS_SHORTNAME",groupingMode:null,groupGranularity:null,groupPrecision:null}])']): this.completeFields is undefined
              at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
              at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
              at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
              at com.smartgwt.client.widgets.BaseWidget.setProperty(BaseWidget.java)
              at com.smartgwt.client.widgets.BaseWidget.setAttribute(BaseWidget.java:721)
              at com.smartgwt.client.widgets.grid.ListGrid.setGroupState(ListGrid.java:5640)
              at com.lmscompany.lms.client.util.ViewStateHelper.applySavedViewStates(ViewStateHelper.java:76)
              at com.lmscompany.lms.client.list.LeadlistMyLeads.configure(LeadlistMyLeads.java:148)
              at com.lmscompany.lms.client.list.LeadlistMyLeads.<init>(LeadlistMyLeads.java:107)
              at com.lmscompany.lms.client.menu.toptabs.LeadpickingVLayout$3.<init>(LeadpickingVLayout.java:54)
              at com.lmscompany.lms.client.menu.toptabs.LeadpickingVLayout.<init>(LeadpickingVLayout.java:54)
              at com.lmscompany.lms.client.menu.navigation.MainArea$4$1.onTabSelected(MainArea.java:168)
              at com.smartgwt.client.widgets.tab.events.TabSelectedEvent.dispatch(TabSelectedEvent.java:107)
              at com.smartgwt.client.widgets.tab.events.TabSelectedEvent.dispatch(TabSelectedEvent.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.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
              at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
              at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
              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:347)
              at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
              at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
              at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
              at java.lang.Thread.run(Unknown Source)
          As you can see I provided DataSource and ListGridFields before calling setGroupState().

          Is this expected behavior? I'd think no, because my other parts of setViewState (=setFieldState() and setSortState()) work for me at that place. I did not use setSelectionState() or setHiliteState().

          Is this a bug? Is it related to the OP's thread?

          Thank you & best regards,
          Blama

          Comment


            #6
            What version of SGWT are you using?

            Comment


              #7
              Found my problem

              Originally posted by Isomorphic View Post
              Something is definitely wrong with the sample code for the SelectItem, we'll fix that. It's not an issue with the setViewState() API or with the framework in general as far as we can see.

              You don't need to wait for draw to call setViewState(), but you do need to do it after you've provided the DataSource and fields if any.
              Just for closure and in case it may help someone else, my problem was the saved viewState string got corrupted. I was not sure where the problem was, but having tested the demo and seeing the SelectItem did not work, I was thinking maybe setViewState(..) was broken. But, as you have pointed out the button on the bottom works, so I digged deeper and found my problem.

              Thank you.

              Comment


                #8
                @Blama Move the setSortState call to the last state call you make (after setGroupState) and it should work for now.

                Comment


                  #9
                  Hi davidj6,

                  thanks, that works. Is this a bug or intended behaviour? If it's intended, it should be noted somewhere that one has to watch the order of calls.

                  Thank you & Best regards,
                  Blama

                  Comment


                    #10
                    Not intended, Blama. Will be addressed soon.

                    Comment


                      #11
                      The sample in question has been fixed now in 4.1

                      Comment


                        #12
                        Just to clarify on when is the best or proper time to call setViewState...

                        "You don't need to wait for draw to call setViewState(), but you do need to do it after you've provided the DataSource and fields if any."

                        Would that be the basic guideline then? I have persisted view states that I load via RPC and was just trying to figure out when the best/proper time to call setViewState on the ListGrid would be?

                        Thanks.

                        Comment


                          #13
                          Yes, that's the guideline.

                          The point is that the viewState modifies the fields. So if the fields haven't been configured, there's no way for the ListGrid to meaningfully interpret the viewState.

                          Comment

                          Working...
                          X