Trouble with updateCaches and database view.

I have a TreeGrid that displays data from a SQL Server view. What I’m having trouble with is making the TreeGrid update after the underlying tables are changed. I realize that in order for the update to happen I will have to notify the DataSource managing the view that there has been a change. The code below is being executed after an insert or update to the the tables that make up the view (there are two tables included in the view). Whenever the code below is executed the entire TreeGrid is emptied and the message “No items to show.” is displayed in the top center of the TreeGrid. No criteria has been set. I’m just trying to load all of the contents of the view.

Please have a look at the code below and, if you wish, please point me in the right direction. Also, if this question has already been posted or something similar to it, please link me to the relevant thread. I’ve already been searching this forum for a couple of hours. I really have tried to refrain from posting a duplicate.

	public void reloadTree(DSResponse response, DSRequest request){
        final DSResponse fwdResponse = new DSResponse ();
        fwdResponse.setInvalidateCache (true);
        Record [] records = response.getData();
        Record [] newRecords = new Record[records.length];
        for (int i = 0; i < records.length; i++){
        	Record record = records[i];
        	Record viewRec = new Record();

        	viewRec.setAttribute("ID", record.getAttributeAsInt("ID"));
        	viewRec.setAttribute("GROUP_ID", 0);
        	viewRec.setAttribute("PARENT_GROUP_ID", record.getAttributeAsInt("GROUP_ID"));
        	viewRec.setAttribute("DISPLAY_NAME", record.getAttribute("DISPLAY_NAME"));
        	viewRec.setAttribute("FILE_NAME", record.getAttribute("FILE_NAME"));
        	viewRec.setAttribute("PUBLISHED", record.getAttribute("PUBLISHED"));
        	newRecords[i] = viewRec;
        }
        fwdResponse.setData (newRecords);
        
        request.setOperationType (DSOperationType.UPDATE);
		DataSource.get("viewReportTree").updateCaches(fwdResponse, request);
	}

Using SmartGWT Pro 2.3
GWT 2.3.0
Google Chrome 13.0.782.112 m
Mozilla Firefox 5.1

Server specs:
Ubuntu 8.04.4 LTS
JBoss Web 2.1.1.CR3

DB
SQL Server 2005

You’re calling setInvalidateCache(true) for some reason - that’s going to wipe out all data that’s been loaded so far (as you’ve discovered).

Thank you very much :smiley: I was misunderstanding the meaning of the function. However, now I’m having another issue. The updates are working great, but when I add a new record it isn’t showing up in the tree as I would expect it to.

I modified the request type from update to add like so:

//changed this...
request.setOperationType (DSOperationType.UPDATE);
//to this:
request.setOperationType (DSOperationType.ADD);

But it made no difference.

What else do I need to change to get the add operation to work?

Make sure the data for the “add” specifies a valid parent. If it’s meant to be added to root, make sure it matches whatever you’ve configured for tree.rootValue.

I just want to make sure I understand you clearly. I have two fields that define the tree structure, GROUP_ID and PARENT_GROUP_ID. If a record is a child of another record then its PARENT_GROUP_ID will link to another record’s GROUP_ID. In my code the PARENT_GROUP_ID is getting set correctly, but the new record still isn’t showing up. However, if I create a new record as a root level item, it shows up instantly.

So are you saying that I should make sure that the PARENT_GROUP_ID and GROUP_ID fields are being set correctly or is there some other property I need to set?

That’s what you need to set correctly. You can enable the “ResultTree” log category in the Developer Console to see whether the ResultTree agrees that your settings are correct :slight_smile:

Thank you lots for all the help. I hope you fall into a cloud of cotton candy on your way home (and that you like cotton candy).