Announcement

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

    Error when deleting records and updating editorProperties in listGrid

    Hi

    I have quite a special case regarding deletion of records and editorProperties in listGrids and can't figure out whether i'm doing something wrong or there is a bug in the listGrids implementation.

    I created a quick example to demonstrate the issue:

    Code:
    public class Test implements EntryPoint {
    
    	@Override
    	public void onModuleLoad() {
    		
    		GWT.create(BeanFactory.FormItemMetaFactory.class);
    		
    		final VLayout layout = new VLayout();
    		layout.setHeight(300);
    		layout.setWidth(700);
    		
    		final ListGrid listGrid = new ListGrid();
    		listGrid.setWidth100();
    		listGrid.setHeight100();
    		listGrid.setShowRowNumbers(false);
    		listGrid.setShowHeader(true);
    		listGrid.setCanEdit(true);
    		listGrid.setEditByCell(true);
    		listGrid.setAlwaysShowEditors(true);
    		listGrid.setShowAllRecords(true);
    		listGrid.setShowAllColumns(true);
    		listGrid.setShowFilterEditor(false);
    		listGrid.setAutoFetchData(false);
    		listGrid.setCanRemoveRecords(true);
    		listGrid.setSelectionType(SelectionStyle.NONE);
    
    		final ListGridField listGridField = new ListGridField("testField", "TestField"){
    			{
    				setAlign(Alignment.LEFT);
    				setEditorType(ComboBoxItem.class);
    			}
    		};
    		
    		listGrid.addDrawHandler(new DrawHandler() {
    
    			@Override
    			public void onDraw(DrawEvent event) {
    				listGrid.setData(new Record[]{
    						new Record(){
    							{
    								setAttribute("testField","test1");
    							}
    						},
    						new Record(){
    							{
    								setAttribute("testField","test2");
    							}
    						}
    				});
    			}
    		});
    
    		listGrid.setFields(listGridField);
    
    		layout.addMember(listGrid);
    		layout.addMember(new IButton("Update"){
    			{
    				addClickHandler(new ClickHandler() {
    					
    					@Override
    					public void onClick(ClickEvent event) {
    						updateListGrid(listGrid,listGridField);
    					}
    				});
    			}
    		});
    		
    		layout.draw();
    	}
    
    	private void updateListGrid(final ListGrid listGrid, final ListGridField listGridField) {
    
    		listGridField.setEditorProperties(new ComboBoxItem(){
    			{
    				// the valueMap may change and therefore needs to
    				// be ypdatedevery time updateListGrid() is called
    				setValueMap(new String[] { "test" });
    			}
    		});
    
    		listGrid.setFields(listGridField);
    
    		// the data are normally parsed from an XML (may have changed) every
    		// time updateListGrid() is called
    		listGrid.setData(new Record[]{
    				new Record(){
    					{
    						setAttribute("testField","test1");
    					}
    				}
    		});
    	}
    }
    Steps to produce the error:

    1. delete all records in the listGrid by clicking the delete icon on the right.
    2. click the Update button to update the editorProperties + listGrid data.

    Doing so results in the following error once the last record is deleted:

    Code:
    17:40:06.299:TMR0:WARN:Log:TypeError: Cannot read property 'getItems' of null
    Stack from error.stack:
    	ListGrid.clearingInactiveEditorHTML(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:1440:376
    	GridBody.redraw(<no args: exited>) on [GridBody ID:isc_ListGrid_0_body] @ ISC_Grids.js:771:48
    	ListGrid.redrawChildren(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2072:554
    	ListGrid.updateHTML(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2065:30
    	ListGrid.redraw(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2061:705
    	[a][c]Class.invokeSuper(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:260:162
    	ListGrid.redraw(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:1004:6
    	ListGrid.removeDataAnimationComplete(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:2272:257
    	[c]Class.fireCallback(_1=>Obj, _2=>undef, _3=>Array[0], _4=>[GridBody ID:isc_ListGrid_0_body], _5=>true) @ ISC_Core.js:269:49
    	[a]ListGrid.fireCallback(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:337:302
    And the following error once update is clicked:

    Code:
    17:41:56.732:TMR6:WARN:Log:TypeError: Cannot read property 'getItems' of null
    Stack from error.stack:
    	ListGrid.clearingInactiveEditorHTML(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:1440:376
    	GridBody.redraw(<no args: exited>) on [GridBody ID:isc_ListGrid_0_body] @ ISC_Grids.js:771:48
    	[c]Canvas.clearRedrawQueue(<no args: exited>) @ ISC_Core.js:2902:110
    	[c]Class.fireCallback(_1=>Obj, _2=>undef, _3=>Array[0], _4=>[Class Canvas], _5=>true) @ ISC_Core.js:269:78
    	Timer._fireTimeout(_1=>"$ir44", _2=>56, _3=>undef) @ ISC_Core.js:1269:222
    	<anonymous>() @ ISC_Core.js:1267:40
    Now i need an option for the user to delete records from the grid.
    At the same time i need to be able to update the valueMap of the comboboxItem and the displayed records, since the suggestions + data can change.
    (These updates always happen before or after the user is able to delte records)

    I've already played around quite a bit, but couldn't find a solution to avoid these errors.

    I'm using the latest build available as of writing this post (27.05.2015).

    Maybe anyone has an idea?

    Thanks in advance and best regards,
    Seraksab
    Last edited by seraksab; 28 May 2015, 07:48. Reason: forgot to mention the used build

    #2
    This code is incorrect in two ways:

    1. you can't make further changes to a ListGridField once you've called setFields()

    2. you can't make further changes to the editorProperties once you've called setFields()

    Instead, there is a dedicated API for this - setEditorValueMap().

    Comment


      #3
      Hi

      I was able to fix the error and get the wanted behaviour by using setEditorValueMap() as opposed to my previous attempt.

      Big thanks for the quick and helpful reply!


      EDIT:

      I guess i have to bother you again.
      Using setEditorValueMap() solved the main problem i had, but there's still an issue:

      Using the test class provided above (without the button and update method):

      Code:
      public class Test implements EntryPoint {
      
      	@Override
      	public void onModuleLoad() {
      		
      		GWT.create(BeanFactory.FormItemMetaFactory.class);
      		
      		final VLayout layout = new VLayout();
      		layout.setHeight(300);
      		layout.setWidth(700);
      		
      		final ListGrid listGrid = new ListGrid();
      		listGrid.setWidth100();
      		listGrid.setHeight100();
      		listGrid.setShowRowNumbers(false);
      		listGrid.setShowHeader(true);
      		listGrid.setCanEdit(true);
      		listGrid.setEditByCell(true);
      		listGrid.setAlwaysShowEditors(true);
      		listGrid.setShowAllRecords(true);
      		listGrid.setShowAllColumns(true);
      		listGrid.setShowFilterEditor(false);
      		listGrid.setAutoFetchData(false);
      		listGrid.setCanRemoveRecords(true);
      		listGrid.setSelectionType(SelectionStyle.NONE);
      
      		final ListGridField listGridField = new ListGridField("testField", "TestField"){
      			{
      				setAlign(Alignment.LEFT);
      				setEditorType(ComboBoxItem.class);
      			}
      		};
      		
      		listGrid.addDrawHandler(new DrawHandler() {
      
      			@Override
      			public void onDraw(DrawEvent event) {
      				listGrid.setData(new Record[]{
      						new Record(){
      							{
      								setAttribute("testField","test1");
      							}
      						},
      						new Record(){
      							{
      								setAttribute("testField","test2");
      							}
      						}
      				});
      			}
      		});
      
      		listGrid.setFields(listGridField);
      		layout.addMember(listGrid);
      		layout.draw();
      	}
      }
      I still get the following error on the Developer Console right after i click the delete icon on the last record in the grid:

      Code:
      10:47:42.755:TMR3:WARN:Log:TypeError: Cannot read property 'getItems' of null
      Stack from error.stack:
      	ListGrid.clearingInactiveEditorHTML(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:1440:376
      	GridBody.redraw(<no args: exited>) on [GridBody ID:isc_ListGrid_0_body] @ ISC_Grids.js:771:48
      	ListGrid.redrawChildren(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2072:554
      	ListGrid.updateHTML(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2065:30
      	ListGrid.redraw(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:2061:705
      	[a][c]Class.invokeSuper(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:260:162
      	ListGrid.redraw(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:1004:6
      	ListGrid.removeDataAnimationComplete(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Grids.js:2272:257
      	[c]Class.fireCallback(_1=>Obj, _2=>undef, _3=>Array[0], _4=>[GridBody ID:isc_ListGrid_0_body], _5=>true) @ ISC_Core.js:269:49
      	[a]ListGrid.fireCallback(<no args: exited>) on[ListGrid ID:isc_ListGrid_0] @ ISC_Core.js:337:302
      This appeared to not have any visual or functional consequences for the listGrid at first.

      But my listGrids is a member of resizable sectionStack.
      This results in the following problems:
      - resizing the sectionStack (and consequently also to listGrid) does not work properly any more
      - Collapsing/expanding other sections of the same sectionStack is no longer possible at all

      As already mentioned, i'm currently using the latest build available as of May 27th.

      Maybe you can have look at this?

      Thanks and best regards,
      Seraksab
      Last edited by seraksab; 29 May 2015, 01:05. Reason: still an error

      Comment

      Working...
      X