Announcement

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

    update TileGrid Tiles periodically

    Hi,

    I'm using a Tilegrid with a DataSource to visualize images. The records fetched, and showed correctly (when I call fetchData()). However the content changes ( on the server), and I would like to update the grid periodically. I tried different ways, but couldn't find the right solution.

    my datasource look like this:

    Code:
    public ExperimentDataSource(String id, String folder, String strsearch ) {  
      setID(id);
      setCacheAllData(true);
      setCacheMaxAge(2);
      setDataFormat(DSDataFormat.XML);  
      setRecordXPath("/contents/item");  
      DataSourceField NodeName = new DataSourceField("name", FieldType.TEXT,  "Name");
      DataSourceField NodeType = new DataSourceField("type", FieldType.TEXT,  "Type");
      DataSourceField NodeImg = new DataSourceField("img", FieldType.IMAGE );
      NodeImg.setImageWidth(170);
      NodeImg.setImageHeight(170);
            
      DataSourceField NodePath = new DataSourceField("path", FieldType.TEXT,  "Path");
            
      setFields(NodeName, NodeType, NodeImg, NodePath);
    }
    The tilegrid:
    Code:
    public ExperimentTileGrid( String dataSourceID, String sfolder ) {
      setTileWidth(200);  
      setTileHeight(200);
      setOverflow(Overflow.VISIBLE);
      setShowEdges( false );
      experimentDataSource = new ExperimentDataSource(dataSourceID, sfolder, "");
      setDataSource(experimentDataSource);
      addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
        // some code, sending request.
      }
    I set up a timer in onModuleLoad(), like this:
    Code:
    Timer t = new Timer() {
      // @Override
      public void run() {
        experimentTileGrid.invalidateCache();
        experimentTileGrid.fetchData();
      }
    };
    t.scheduleRepeating(3000);
    What I experience:
    - It seems like the tilegrid has updated (I see the loading gif), but there's no request to the server, and the images are the same. plus every time the timer runs, the DoubleClickHandler called (it sounds a bug for me)!

    I quite sure that something wrong in my code, please give me some hint about how to update the Tiles of a Tilegrid periodically.

    I'm using smartgwt 2.5 with chrome 15.0.874.106
    Thanks
    B.

    #2
    Call invalideCache() without also calling fetchData().

    Note, do not test in GWT development with Chrome, it's broken (see FAQ).

    Comment


      #3
      if I call just invalidateCache() it just clears the Tiles, without any request to the server. I tried to call the invalidateCache() of the datasource, but than nothing happens.

      The problem is in the compiled version, anyway thank you for this info.

      Comment


        #4
        Your suggestion about just calling invalidateCache() didn't worked for me, and couldn't solved by myself. So I would post some test case, hope it's in a right format, and you can use it. This is the content of the onModuleLoad:
        Code:
        RootPanel rootPanel = RootPanel.get();
        
        final TileGrid tileGrid = new TileGrid();
        tileGrid.setSize("607px", "296px");
        tileGrid.setTileWidth(200);  
        tileGrid.setTileHeight(200);
        tileGrid.setOverflow(Overflow.VISIBLE);
        	    
        DataSource expDS = new DataSource("/response.xml");
        //expDS.setCacheAllData(true);
        //expDS.setCacheMaxAge(2);
        expDS.setDataFormat(DSDataFormat.XML);  
        expDS.setRecordXPath("/contents/item");  
        DataSourceField NodeName = new DataSourceField("name", FieldType.TEXT,  "Name");
        DataSourceField NodeType = new DataSourceField("type", FieldType.TEXT,  "Type");
        DataSourceField NodeImg = new DataSourceField("img", FieldType.IMAGE );
        NodeImg.setImageWidth(170);
        NodeImg.setImageHeight(170);
        DataSourceField NodePath = new DataSourceField("path", FieldType.TEXT,  "Path");               
        expDS.setFields(NodeName, NodeType, NodeImg, NodePath);	    
        tileGrid.setDataSource(expDS);
        tileGrid.setAutoFetchData(true);
        
        tileGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {			
          @Override
          public void onRecordDoubleClick(RecordDoubleClickEvent event) {
            Window.alert("dbl click!");
          }
        });
                
        rootPanel.add(tileGrid);
        
        Timer t = new Timer() {
          // @Override
          public void run() {
            tileGrid.invalidateCache();
          }
        };
        t.scheduleRepeating(3000);
        and under war folder I use an xml for the source of dataSource, which looks like this:
        Code:
        <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <contents>
        	<item>
        		<path>/astro/</path>
        		<name>astro</name>
        		<type>folder</type>
        		<img>/folder.png</img>
        	</item>
        	<item>
        		<path>/buggy/</path>
        		<name>buggy</name>
        		<type>folder</type>
        		<img>/folder.png</img>
        	</item>
        	<item>
        		<path>/coulomb/</path>
        		<name>coulomb</name>
        		<type>folder</type>
        		<img>/folder.png</img>
        	</item>
        	<item>
        		<path>/dynamics/</path>
        		<name>dynamics</name>
        		<type>folder</type>
        		<img>/folder.png</img>
        	</item>
        </contents>
        An there's an attached folder.png under war, which is the picture on the tile.
        What you can see in this little testcase is that after the timer executed, the tiles are cleared, not updated. Now in this example these are just files (response.xml, and folder.png) In my real app it's generated by the server.
        Attached Files

        Comment

        Working...
        X