Announcement

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

    Can ListGrid get/set view state include hilite settings?

    I'm looking at the hiliting feature which is very cool, especially the editHilites() dialog letting the user define the hilite conditions. We already have code in place to handle saving and restoring ListGrid settings using get/set ViewState. It doesn't appear that hiliting is included in the view state, or is it? If not, can it be, or do we need to save hiliting separate from the other view state info?

    #2
    It isn't included in the ViewState by default, but, you can combine any of the different state strings together and store the combined blob associated with the grid.

    Comment


      #3
      So I can save a String which is getViewState() + getHiliteState() and then use that combined string to setViewState() and it will also restore the hilite state?

      Comment


        #4
        No, you need to combine and split them yourself (eg, put them both in a JSON object under different property names and serialize that).

        Comment


          #5
          Thanks for the tip. It's the first time I've used JSONObject() and related GWT classes. Here is how I'm saving the view state and hilite state together.
          Code:
          JSONObject combinedState = new JSONObject();
          combinedState.put(VIEW_STATE, new JSONString(getViewState()));
          combinedState.put(HILITE_STATE, new JSONString(getHiliteState()));
          String viewState = combinedState.toString();
          And here is how I'm restoring them.
          Code:
          JSONValue combinedValue = JSONParser.parseLenient(savedState);
          JSONObject combinedObj = combinedValue.isObject();
          JSONValue viewState = combinedObj.get(VIEW_STATE);
          if (viewState!=null)
          	setViewState(viewState.toString());
          JSONValue hiliteState = combinedObj.get(HILITE_STATE);
          if (hiliteState!=null)
          	setHiliteState(hiliteState.toString());
          The view state gets restored correctly, but setHiliteState() generates the following js error.
          Code:
          com.google.gwt.core.client.JavaScriptException: (TypeError): _1.makeIndex is not a function
           fileName: http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js
           lineNumber: 3511
           stack: isc_Canvas__setupHilites("([\r    {\r        \"fieldName\":\"IRET\", \r        \"criteria\":{\r            \"fieldName\":\"IRET\", \r            \"operator\":\"greaterThan\", \r            \"value\":10\r        }, \r        \"textColor\":\"#000080\", \r        \"cssText\":\"color:#000080;\", \r        \"id\":0\r    }\r])")@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:3511
          isc_Canvas_setHilites("([\r    {\r        \"fieldName\":\"IRET\", \r        \"criteria\":{\r            \"fieldName\":\"IRET\", \r            \"operator\":\"greaterThan\", \r            \"value\":10\r        }, \r        \"textColor\":\"#000080\", \r        \"cssText\":\"color:#000080;\", \r        \"id\":0\r    }\r])")@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:3507
          isc_Canvas_setHiliteState("\"([\\r    {\\r        \\\"fieldName\\\":\\\"IRET\\\", \\r        \\\"criteria\\\":{\\r            \\\"fieldName\\\":\\\"IRET\\\", \\r            \\\"operator\\\":\\\"greaterThan\\\", \\r            \\\"value\\\":10\\r        }, \\r        \\\"textColor\\\":\\\"#000080\\\", \\r        \\\"cssText\\\":\\\"color:#000080;\\\", \\r        \\\"id\\\":0\\r    }\\r])\"")@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:3509
          ("\"([\\r    {\\r        \\\"fieldName\\\":\\\"IRET\\\", \\r        \\\"criteria\\\":{\\r            \\\"fieldName\\\":\\\"IRET\\\", \\r            \\\"operator\\\":\\\"greaterThan\\\", \\r            \\\"value\\\":10\\r        }, \\r        \\\"textColor\\\":\\\"#000080\\\", \\r        \\\"cssText\\\":\\\"color:#000080;\\\", \\r        \\\"id\\\":0\\r    }\\r])\"")@http://127.0.0.1:8888:1990
          @:0
          ([object GWTJavaObject],18350082,[object XMLHttpRequest])@http://127.0.0.1:8888/ipgui/hosted.html?ipgui:56
          ([object Event])@http://127.0.0.1:8888:10
          ((function () {__gwt_makeJavaInvoke(1)(handler, 18350082, _this);}),[object XMLHttpRequest],[object Object])@http://127.0.0.1:8888:77
          @:0
          (null,106,(function () {__gwt_makeJavaInvoke(1)(handler, 18350082, _this);}),[object XMLHttpRequest],[object Object])@http://127.0.0.1:8888/ipgui/hosted.html?ipgui:56
          ([object Event])@http://127.0.0.1:8888:26
          
          	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
          	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
          	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
          	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
          	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
          	at com.smartgwt.client.widgets.grid.ListGrid.setHiliteState(ListGrid.java)
          	at com.islandpacific.gui.client.IpListGrid$28.onSuccess(IpListGrid.java:1168)
          	at com.islandpacific.gui.client.IpListGrid$28.onSuccess(IpListGrid.java:1)
          	at com.islandpacific.gui.client.IpAuthenticationContext$4.onSuccess(IpAuthenticationContext.java:262)
          	at com.islandpacific.gui.client.IpAuthenticationContext$4.onSuccess(IpAuthenticationContext.java:1)
          	at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
          	at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
          	at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
          	at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:597)
          	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:157)
          	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
          	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
          	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
          	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
          	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
          	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:214)
          	at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:597)
          	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:157)
          	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
          	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
          	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
          	at java.lang.Thread.run(Thread.java:680)

          Comment


            #6
            Looks like JSONParser.parseLenient has bugs related to creating JavaScript objects in the wrong frame. Use our JSON.decode() method instead.

            Comment


              #7
              JSON.decode() gives me a JavaScriptObject but how do I access the two attribute strings within it?

              Comment


                #8
                I changed the code that restores the saved state to this, but I'm still getting the same js error when calling setHiliteState.
                Code:
                JavaScriptObject combinedValue = JSON.decode(savedState);
                JSONObject combinedObj = new JSONObject(combinedValue);
                JSONValue viewState = combinedObj.get(VIEW_STATE);
                if (viewState!=null)
                	setViewState(viewState.toString());
                JSONValue hiliteState = combinedObj.get(HILITE_STATE);
                if (hiliteState!=null)
                	setHiliteState(hiliteState.toString());
                Do I need to change the way I'm serializing it when saving to use JSON.encode()? If so, how do I transform the results of getViewState() and getHiliteState() into a JavaScriptObject?

                Comment


                  #9
                  Oh, actually, you may be tripping a different GWT bug. Try just casting viewState/hiliteState to String instead of calling toString().

                  Comment


                    #10
                    Trying setHiliteState((String) hiliteState); but "Cannot cast from JSONValue to String"

                    Comment


                      #11
                      Sorry for the confusion. If you look at the stack trace you can see that what's happening is double encode and single decode. The string we return from getHiliteState() and that we expect back is ready to eval and will produce a JavaScript Array. It's unclear how (you haven't shown complete code as of last updates) but you're passing a string that would need to be eval()d twice to produce an Array.

                      Comment


                        #12
                        I see what you mean. This is my latest attempt and I still can't seem to get the right combination of conversions to/from JSON. This is how I'm saving the save into a combined String, which is then saved in a Record using Record.setAttribute("savedState", combinedState).
                        Code:
                        JSONObject combinedStateObj = new JSONObject();
                        String viewState = getViewState();
                        if (viewState!=null)
                        	combinedStateObj.put(VIEW_STATE, new JSONString(viewState));
                        String hiliteState = getHiliteState();
                        if (hiliteState!=null)
                        	combinedStateObj.put(HILITE_STATE, new JSONString(hiliteState));
                        String combinedState = combinedStateObj.toString();
                        And this is how I'm decoding into Strings to reset the state.
                        Code:
                        JavaScriptObject combinedValue = JSON.decode(savedState);
                        JSONObject combinedObj = new JSONObject(combinedValue);
                        if (combinedObj.containsKey(VIEW_STATE)) {
                        	JSONString viewState = (JSONString) combinedObj.get(VIEW_STATE);
                        	setViewState(viewState.toString());
                        }
                        if (combinedObj.containsKey(HILITE_STATE)) {
                        	JSONString hiliteState = (JSONString) combinedObj.get(HILITE_STATE);
                        	setHiliteState(hiliteState.toString());
                        }
                        Last edited by jay.l.fisher; 3 Dec 2010, 15:25.

                        Comment


                          #13
                          The docs for JSONObject and friends are a little unclear about when and how things are being encoded, but there's a suggestion that using new JSONString() is creating an extra level of quoting relative to new JSONValue(). If that's not it, it's probably best to step through and see where the extra quoting happens.

                          Or, really, using JSNI to form the object to serialize is actually going to be shorter, clearer code than going through the JSONObject API.

                          Comment


                            #14
                            An example would be welcome. I've got this JSNI creating a JavaScriptObject which I then persist to the database without trying to convert it to a String, just using Record.setAttribute("savedState", getCombinedState(getViewState(), getHiliteState());
                            Code:
                            public static native JavaScriptObject getCombinedState(String viewState, String hiliteState) /*-{
                              var returnObj = new Object();
                              returnObj.viewState = viewState;
                              returnObj.hiliteState = hiliteState;
                              return returnObj;
                            }-*/;
                            But then how do I parse it back into something that let's me get to the two String attributes? JSON.decode() doesn't like the format.
                            Code:
                            com.google.gwt.core.client.JavaScriptException: (SyntaxError): missing : after property id
                             fileName: http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js
                             lineNumber: 3827
                             stack: eval("({viewState=({selected:null,field:\"[\\r    {\\r        name:\\\"_checkboxField\\\", \\r        width:28\\r    }, \\r    {\\r        name:\\\"ItemNumber\\\", \\r        width:null\\r    }, \\r    {\\r        name:\\\"IDES\\\", \\r        width:null\\r    }, \\r    {\\r        name:\\\"IVST\\\", \\r        width:null\\r    }, \\r    {\\r        name:\\\"IPPK\\\", \\r        width:null\\r    }, \\r    {\\r        name:\\\"IRET\\\", \\r        width:null\\r    }, \\r    {\\r        name:\\\"IVNC\\\", \\r        visible:false, \\r        width:null\\r    }, \\r    
                            
                            ...... the full stack is too long to post
                            
                              sortDir:true, \\r    sortSpecifiers:[\\r        {\\r            property:\\\"ItemNumber\\\", \\r            direction:\\\"ascending\\\"\\r        }\\r    ]\\r})\"}), hiliteState=null}")@http://127.0.0.1:8888:14

                            Comment


                              #15
                              The JSNI method is fine, but just sticking the JavaScriptObject directly into the Record is probably not what you want to do (not really clear in your system how that's even working..).

                              Given your JavaScriptObject, you should now be in a position to use pure SmartGWT JSON APIs for encode/decode and avoid any ambiguity.

                              If you have any trouble with that, please show the code, and also the values you see at various spots (full encoded String of the combined object, Strings that you pass to setHiliteState() and setViewState()).

                              Comment

                              Working...
                              X