Announcement

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

    listgrid viewstate selected

    Is there an easy way to omit setting the selected property coming from the viewstate? It is causing some issues in IE8 and not exactly sure what the problem is yet but it has to do with invalidatecache and setViewState being called. We get an error saying this.localData is null.

    I just need to workaround this for now. I looked at the stacktrace and the error comes from:

    anonymous
    isc_Arra_findByKeys
    isc_listGrid_setSelectedState
    isc_ListGrid_dataChanged
    anonymous
    isc_ResultSet_invalidatecache

    I have reason to suspect it is the combination of our call to invalidateCache and setViewState (which are done independently) because if I comment one of the two then it works fine.


    Note that this problem is not visible in IE9, or FF5. If I revert to 06-17 build from 08-16, it is also fine.
    Last edited by acarur01; 26 Aug 2011, 10:02.

    #2
    Omitting the selected state from the viewState is not likely to be the easiest fix here. We would probably be able to suggest something easier if you provided a real stack trace (from the Developer Console as usual).

    However if you wanted to approach this via viewState, it's really just a String of serialized JSON, so you could eval() it to turn it into an object, delete the selected state (it's obvious where it is if you just echo() the object) and re-serialize it as JSON using the JSONEncoder before passing it to the setViewState() method.

    Comment


      #3
      I managed to work around it by override setSelectedState:


      setSelectedState: function(selectedState){
      if(this.localData==null){
      return;
      }else{
      this.Super("setSelectedState", selectedState);
      }

      }

      but I will provide the stacktrace as well in a few

      Comment


        #4
        Here is the last Request/Response when the error happens:


        DSRequest
        Code:
        {
            "dataSource":"page$content$$content$resultFrame$ResultPortalSectionss$result$ds", 
            "operationType":"fetch", 
            "componentId":"page$content$$content$resultFrame$ResultPortalSectionss$result", 
            "data":{
            }, 
            "startRow":0, 
            "endRow":75, 
            "textMatchStyle":"exact", 
            "resultSet":[ResultSet ID:isc_ResultSet_0 (created by: page$content$$content$resultFrame$ResultPortalSectionss$result)], 
            "callback":{
                "caller":[ResultSet ID:isc_ResultSet_0 (created by: page$content$$content$resultFrame$ResultPortalSectionss$result)], 
                "methodName":"fetchRemoteDataReply"
            }, 
            "willHandleError":true, 
            "showPrompt":false, 
            "prompt":"Finding records that match your criteria...", 
            "oldValues":{
            }, 
            "clientContext":{
                "requestIndex":2
            }, 
            "requestId":"page$content$$content$resultFrame$ResultPortalSectionss$result$ds$6272"
        }
        DSResponse

        Code:
        [
            {
                endRow:1, 
                queueStatus:0, 
                totalRows:1, 
                isDSResponse:true, 
                invalidateCache:false, 
                status:0, 
                startRow:0, 
                data:[
                    {
                        cwPK__:"296145000", 
                        $isCwSelected:true, 
                        documentType:"Announcement", 
                        documentType$L:{
                            announcement:"Announcement"
                        }, 
                        documentType$k:"", 
                        productLineInfoForTheDoc:"", 
                        documentTitle:"fateafa", 
                        businessId:"", 
                        validFrom:new Date(1314244800000), 
                        validTo:new Date(1314676800000), 
                        imageCalculate:"/cwf/MenuIconAttach.gif", 
                        image$imageWidth:15, 
                        image$imageHeight:18
                    }
                ]
            }
        ]
        And the error in the console:

        Code:
        
        15:09:02.958:WARN:Log:Error:
        	''this.localData' is null or not an object'
        	in http://localhost:8080/cwf/isomorphic/system/modules/ISC_Core.js?v=50253
        	at line 591
            ResultSet.findNextIndex(a=>undef, b=>Obj, c=>null, d=>undef, e=>undef, f=>undef, g=>undef, h=>undef, i=>undef, j=>undef, k=>undef, l=>undef, m=>undef, n=>undef, o=>undef, p=>undef)
                "return this.localData.findNextIndex(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)"
            Array.findByKeys(_1=>Obj, _2=>[DataSource ID:page$content$$content$resultFrame$ResultCIHSectionss$result$ds], _3=>undef, _4=>undef)
            ListGrid.setSelectedState(_1=>Array[1])
            ListGrid.dataChanged(_1=>null, _2=>null, _3=>null, _4=>null, _5=>true)
            dataChangedObservation(operationType=>null, originalRecord=>null, rowNum=>null, updateData=>null, filterChanged=>true)
            ResultSet.invalidateCache()
            Canvas.invalidateCache()
            Class.invokeSuper(_1=>null, _2=>"invalidateCache", _3=>undef, _4=>undef, _5=>undef, _6=>undef, _7=>undef, _8=>undef, _9=>undef, _10=>undef)
            Class.Super(_1=>"invalidateCache", _2=>Obj{length:0}, _3=>undef)
            ListGrid.invalidateCache()

        Comment


          #5
          Let me know if there's anything you can tell that is wrong from the log. This is kind of hard to reproduce as a standalone

          Comment


            #6
            This suggests that you've use observe() to watch dataChanged() and are calling setSelectedState() in your observation. But it would be invalid to do this right after flushing the cache. You can detect that you're in this state with resultSet.lengthIsKnown().

            Comment


              #7
              Actually, I don't even know what dataChangedObservation is and I do not call setSelectedState anywhere in our code. The only call I do is invalidateCache. I can provide you a screenshot of the stacktrace in IE debug if that would help

              Comment


                #8
                Given the stack trace, coupled with the fact that you're not observing dataChanged in your application code, we've been able to pin down what's almost certainly responsible for this in the framework code.
                We've made a change that should avoid the bug. This fix will show up in nightly builds going forward (however your workaround of disabling 'setSelectedState' will also resolve the issue for you).

                Comment


                  #9
                  Awesome, thanks!

                  Comment


                    #10
                    Hi,

                    I'm also not interested in letting ViewState manage the selected state at this time, so I tried this approach:

                    Originally posted by Isomorphic View Post
                    if you wanted to approach this via viewState, it's really just a String of serialized JSON, so you could eval() it to turn it into an object, delete the selected state (it's obvious where it is if you just echo() the object) and re-serialize it as JSON using the JSONEncoder before passing it to the setViewState() method.
                    using
                    Code:
                    // delete 'selected' for now
                    JavaScriptObject jso = JSON.decode(previouslySavedState);
                    JSOHelper.deleteAttribute(jso, "selected");
                    JSONEncoder settings = new JSONEncoder();
                    settings.setStrictQuoting(false);
                    previouslySavedState = "(" + JSON.encode(jso, settings) + ")";
                    this.setViewState(previouslySavedState);
                    but it still breaks a case where we 'always select the first row' in a grid (regardless if it's the one selected before).

                    When I check the JS code:
                    Code:
                    setViewState : function (state) {
                        state = this.evalViewState(state, "viewState")
                        if (!state) return;
                    
                        // Order is somewhat important - for example show fields before potentially sorting 
                        // by them, etc
                        if (state.field) this.setFieldState(state.field);
                        this.setSortState(state.sort);
                        this.setGroupState(state.group);
                        this.setHiliteState(state.hilite);
                        this.setSelectedState(state.selected);
                    },
                    
                    
                    setSelectedState : function (selectedState) {
                        
                        selectedState = this.evalViewState(selectedState, "selectedState")
                        if (!selectedState || selectedState.length == 0) {
                            if (this.selection) this.selection.deselectAll();
                            return;
                        }
                    ...
                    so I assume that even when deleting the "selected" attribute there, I always end up with no records selected because of "this.selection.deselectAll()".

                    In setViewState you check on "if (state.field)" but not on "if (state.selected)", would it make sense to add it there as I think it would solve my case?

                    If possible of course, an easier way to control (maybe as parameters to the setViewState method) what view state resets would be better than manually deleting that attribute.


                    This is in SNAPSHOT_v8.3d_2012-10-11/Pro Deployment (built 2012-10-11), not yet verified with the latest nightly.

                    Comment


                      #11
                      The right way to handle this with current framework code is going to be to call getXXXState() and setXXXState() for each sub-type of viewState you're interested in.
                      That allows you to selectively update the field state, group state etc without updating selection.

                      These APIs are not currently public but we're exposing them now - you should see them show up in the next nightly build (3.1d / 4.0d branches)

                      Comment


                        #12
                        Hi,
                        update on this development:

                        Using v8.3p_2013-04-08/Pro Deployment (built 2013-04-08)
                        I see the new APIs.

                        * Using an addFieldStateChangedHandler, I react to user state changes of ListGrid group/ungroup actions. During that event, I get the getGroupState() string. At that time, getGroupState returns the state *before* the event. So I cannot get to the user's changes.

                        When I manually do getGroupState after the event has handled, its value is as expected.


                        * I tried also using the explicit addGroupByHandler, but it's the same problem.

                        Comment


                          #13
                          We're not seeing this at HQ - can you show some code?

                          In the meantime, can you also check that if you handle viewStateChanged instead of fieldStateChanged, then getGroupState() returns the correct state?

                          Comment


                            #14
                            In fact, field-state would not be expected to change for a grouping change, unless perhaps the grouped field was also sorted. Grouping changes affect view state, not field state, so you should use a viewState handler instead.

                            If we're misinterpreting, your test code will help to clarify.
                            Last edited by Isomorphic; 25 Apr 2013, 20:11.

                            Comment


                              #15
                              Hi, here's a repro against
                              * v8.3p_2013-04-08/Pro Deployment (built 2013-04-08)
                              * SNAPSHOT_v9.0d_2013-04-15/Pro Deployment (built 2013-04-15)

                              In the output it produces, you can see that when I ungroup the grouped field, the grid returns a string for groupState and even isGrouped is true. (NOK)
                              If you then click on the "check state" button, it outputs an empty string group groupState and isGrouped is false - as expected (OK).


                              * I now notice it is actually going wrong from the start:
                              the init first outputs some groupstate string while isGrouped is false.
                              Then ends with an empty groupstate string and isGrouped is false, but what you see on the UI is that the grid is grouped.


                              Maybe the difference with your testcase was that I already coded the initial grouping state?

                              Code:
                              	public Canvas getViewPanel() {
                              		final MyListGrid grid = new MyListGrid();
                              		grid.setWidth(400);
                              		grid.setHeight(200);
                              		String fieldName1 = "a";
                              		String fieldName2 = "b";
                              		ListGridField field1 = new ListGridField(fieldName1);
                              		ListGridField field2 = new ListGridField(fieldName2);
                              		grid.setFields(field1, field2);
                              		
                              		grid.setSortField(fieldName2);
                              		// Comment this one to make the error go away
                              		grid.setGroupByField(fieldName1);
                              
                              		ListGridRecord record1 = new ListGridRecord();
                              		record1.setAttribute(fieldName1, "aha1");
                              		record1.setAttribute(fieldName2, "oho1");
                              
                              		ListGridRecord record2 = new ListGridRecord();
                              		record2.setAttribute(fieldName1, "aha2");
                              		record2.setAttribute(fieldName2, "oho2");
                              
                              		grid.setRecords(new ListGridRecord[]{record1, record2});
                              		
                              		grid.hideField(fieldName1);
                              		
                              
                              
                              		Button addData = new Button("Check State");
                              		addData.addClickHandler(new ClickHandler() {
                              
                              			public void onClick(ClickEvent event) {
                              				String s = "========Current ViewState: " + grid.getViewState();
                              				System.out.println(s);
                              				s = "..Current GroupState : " + grid.getGroupState();
                              				System.out.println(s);
                              				System.out.println("..Is grouped? " + grid.isGrouped());
                              			}
                              		});
                              		
                              		VLayout layout = new VLayout();
                              		layout.setWidth100();
                              		layout.addMembers(addData, grid);
                              		return layout;
                              	}
                              	
                              	private class MyListGrid extends ListGrid {
                              
                              		public MyListGrid() {
                              			super();
                              			setID("gridxxx1");
                              			setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
                              			
                              			setShowGridSummary(true);	
                              			setShowFilterEditor(true);
                              			setAllowFilterExpressions(true);			
                              			setGroupStartOpen(GroupStartOpen.ALL);
                              			setSelectionType(SelectionStyle.SINGLE);
                              			setOverflow(Overflow.VISIBLE);
                              			
                              			addFieldStateChangedHandler(new FieldStateChangedHandler() {
                              				
                              				@Override
                              				public void onFieldStateChanged(FieldStateChangedEvent event) {
                              					
                              					String s = "========Viewstate changed: " + MyListGrid.this.getViewState();
                              					System.out.println(s);
                              					s = "..Current GroupState : " + MyListGrid.this.getGroupState();
                              					System.out.println(s);
                              					System.out.println("..Is grouped? " + MyListGrid.this.isGrouped());
                              				}
                              			});
                              			
                              			addGroupByHandler(new GroupByHandler() {
                              				
                              				@Override
                              				public void onGroupBy(GroupByEvent event) {
                              					
                              					String s = "========GroupBy changed: " + MyListGrid.this.getViewState();
                              					System.out.println(s);
                              					s = "..Current GroupState : " + MyListGrid.this.getGroupState();
                              					System.out.println(s);
                              					System.out.println("..Is grouped? " + MyListGrid.this.isGrouped());
                              				}
                              			});
                              		}
                              
                              	}

                              output and steps performed:
                              Code:
                              ======== start up the sample
                              
                              ========Viewstate changed: ({selected:null,field:"[{name:\"a\",width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:"([{fieldName:\"a\",groupingMode:null,groupGranularity:null,groupPrecision:null}])"})
                              ..Current GroupState : ([{fieldName:"a",groupingMode:null,groupGranularity:null,groupPrecision:null}])
                              ..Is grouped? false
                              ========Viewstate changed: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:"([{fieldName:\"a\",groupingMode:null,groupGranularity:null,groupPrecision:null}])"})
                              ..Current GroupState : ([{fieldName:"a",groupingMode:null,groupGranularity:null,groupPrecision:null}])
                              ..Is grouped? false
                              ========Viewstate changed: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:"([{fieldName:\"a\",groupingMode:null,groupGranularity:null,groupPrecision:null}])"})
                              ..Current GroupState : ([{fieldName:"a",groupingMode:null,groupGranularity:null,groupPrecision:null}])
                              ..Is grouped? false
                              ========GroupBy changed: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:""})
                              ..Current GroupState : 
                              ..Is grouped? false
                              
                              
                              ================== startup ended
                              
                              
                              
                              === left click the ListGrid header arrow which appear
                              === choose ungroup
                              
                              ========GroupBy changed: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:"([{fieldName:\"a\",groupingMode:null,groupGranularity:null,groupPrecision:null}])"})
                              ..Current GroupState : ([{fieldName:"a",groupingMode:null,groupGranularity:null,groupPrecision:null}])
                              ..Is grouped? true
                              ========Viewstate changed: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:"([{fieldName:\"a\",groupingMode:null,groupGranularity:null,groupPrecision:null}])"})
                              ..Current GroupState : ([{fieldName:"a",groupingMode:null,groupGranularity:null,groupPrecision:null}])
                              ..Is grouped? true
                              
                              
                              
                              ==== click the check state button
                              
                              ========Current ViewState: ({selected:null,field:"[{name:\"a\",visible:false,width:null,autoFitWidth:null},{name:\"b\",width:null,autoFitWidth:null}]",sort:"({fieldName:\"b\",sortDir:\"ascending\",sortSpecifiers:[{property:\"b\",direction:\"ascending\"}]})",hilite:null,group:""})
                              ..Current GroupState : 
                              ..Is grouped? false
                              
                              
                              ====
                              After "choose ungroup" I don't expect the groupState to return something.

                              Comment

                              Working...
                              X