Announcement

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

    ResultSet listeners not firing

    This may well be how I am using the ResultSet, but I would very much like to know how to use this correctly.

    Expected: resultSet listeners are fired when edits are made to the ListGrid
    Observed: no calls to the handlers are made

    I want to use the ResultSet handlers to trigger UI component updates (ie, buttons changing/etc) but I've tried numerous ways and can't seem to find out how to make ResultSet work. All I need is an event listener that triggers when the underlying dataset changes.

    Code:
    	private static DataSource getData() {
    		DataSource dataSource = new DataSource();
    		dataSource.setClientOnly(true);
    		DataSourceField keyField = new DataSourceField("1", FieldType.TEXT);
    		keyField.setPrimaryKey(true);
    		dataSource.addField(keyField);
    		dataSource.addField(new DataSourceField("2", FieldType.TEXT));
    		dataSource.addField(new DataSourceField("3", FieldType.TEXT));
    		return dataSource;
    	}
    	
    	private static void generate(DataSource dataSource, int count) {
    		ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>();
    
    		for (int i = 0; i < count; i++) {
    			ListGridRecord record2 = new ListGridRecord();
    			record2.setAttribute("1", "id " + i);
    			record2.setAttribute("2", "e" + Random.nextInt(10));
    			record2.setAttribute("3", "f" + Random.nextInt(3));
    			records.add(record2);
    		}
    		dataSource.setTestData(records.toArray(new ListGridRecord[] {}));
    	}
    
    	public static void testResultSet() {
    		DataSource ds = getData();
    		generate(ds,10);
    		
    		DataArrivedHandler dataArrivedHandler = new DataArrivedHandler() {
    			@Override
    			public void onDataArrived(DataArrivedEvent event) {
    				SC.say(event.toDebugString());
    			}
    		};
    		DataChangedHandler dataChangedHandler = new DataChangedHandler() {
    			@Override
    			public void onDataChanged(DataChangedEvent event) {
    				SC.say(event.toDebugString());
    			}
    		};
    		ResultSet rs = new ResultSet(ds);
    		rs.addDataArrivedHandler(dataArrivedHandler);
    		rs.addDataChangedHandler(dataChangedHandler);
    
    		ListGrid listGrid = new ListGrid();
    		listGrid.setDataSource(ds);
    		listGrid.setAutoFetchData(true);
    		listGrid.setCanEdit(true);
    		listGrid.setWidth100();
    		listGrid.setHeight100();
    		listGrid.show();
    	}

    #2
    You appear to have created a ResultSet, but then done nothing with it. It's not been provided to the ListGrid, and the ListGrid is creating it's own separate ResultSet as usual because of autoFetchData.

    Comment


      #3
      My intent is to create independent a ResultSet that is not connected to a ListGrid. I want it to act as a listener for all changes to a DataSource.

      I should rephrase my question: what is the correct way to cause the ResultSet to become connected to the DataSource and start firing change events?

      I have tried ResultSet.toArray() - and this works in hosted mode but causes a silent javascript crash (no idea where) when I compile it with GWT.

      Comment


        #4
        Cause it to fetch. One way to do so is to call get(0).

        Comment


          #5
          Ok, thanks. This is a pretty useful feature of SmartGWT.

          The docs could be more clear on how to correctly use a ResultSet as a datasource listener. (notably, making it clear that the ResultSet listeners will not fire until after the first fetch).

          Thank you for clarifying.

          Directly created ResultSets are typically used by custom components, or as a means of managing datasets that will be used by several components.

          When created directly rather than via a dataBoundComponent, a newly created ResultSet will not issue it's first "fetch" DSRequest until data is accessed (for example, via get(int)).

          Also, the ResultSet.toArray() is perhaps worth checking out as a major bug. It does something nasty in both FF3.6 and Chrome12 (all browsers I tested) and causes GWT to completely stop. And annoyingly, it is just fine in hosted mode.

          Comment

          Working...
          X