Using the latest smartgwt (3.1)... sorry, but I couldn't get the developer console to load to tell me the exact version, but looking at the javascript I imagine it's
isc.version="v8.3_2012-11-20/LGPL Development Only"
I am creating a tree with a datasource whose data is supposed to come from a gwt rpc call. The records are set as PARENT modetype, since I want each open operation on each node to call the GWT rpc.
When I first load the tree, all top level folder icons show appropriate '+' expansion signs, however, when I refresh the data, the '+' signs are gone.
I've tried all kind of things to make it work and nothing does! Please help!
Code follows
isc.version="v8.3_2012-11-20/LGPL Development Only"
I am creating a tree with a datasource whose data is supposed to come from a gwt rpc call. The records are set as PARENT modetype, since I want each open operation on each node to call the GWT rpc.
When I first load the tree, all top level folder icons show appropriate '+' expansion signs, however, when I refresh the data, the '+' signs are gone.
I've tried all kind of things to make it work and nothing does! Please help!
Code follows
Code:
package testGWT.client; import java.util.ArrayList; import java.util.List; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.LayoutPanel; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.types.DSDataFormat; import com.smartgwt.client.types.DSProtocol; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.client.widgets.tree.TreeGridField; import com.smartgwt.client.widgets.tree.TreeNode; public class SmartGWTTest extends LayoutPanel { public class ParentThing { public final String name; public final String primaryKey; public ParentThing(String primaryKey, String name) { super(); this.primaryKey = primaryKey; this.name = name; } } public class MyDataSource extends DataSource { public MyDataSource() { setDataProtocol(DSProtocol.CLIENTCUSTOM); setDataFormat(DSDataFormat.CUSTOM); setClientOnly(false); DataSourceTextField primaryKey = new DataSourceTextField("primaryKey"); primaryKey.setPrimaryKey(true); DataSourceTextField parentId = new DataSourceTextField("parentId"); parentId.setForeignKey("primaryKey"); DataSourceTextField nameField = new DataSourceTextField("nameField"); addField(primaryKey); addField(parentId); addField(nameField); } @Override protected Object transformRequest(DSRequest request) { String requestId = request.getRequestId(); DSResponse response = new DSResponse(); switch (request.getOperationType()) { case FETCH: executeFetch(requestId, request, response); break; default: throw new RuntimeException("Operation " + request.getOperationType() + " not yet permitted"); } return request.getData(); } void executeFetch(final String requestId, final DSRequest request, final DSResponse response) { Criteria criteria = request.getCriteria(); final String parentId = criteria.getAttribute("parentId"); if (parentId != null && !"".equals(parentId)) { // TODO: Retrieve children here processResponse(requestId, response); } else { String searchCriteria = criteria.getAttribute("searchCriteria"); if (searchCriteria == null) { searchCriteria = "0"; } if (searchCriteria != null) { // Fill in the top level List<ParentThing> data = new ArrayList<ParentThing>(); for (int i = 0; i <= 5; ++i) { ParentThing parentThing = new ParentThing("pk" + i, "name " + i); data.add(parentThing); } Record[] records = new Record[data.size()]; int i = 0; for (ParentThing parentThing : data) { String primaryKey = parentThing.primaryKey; TreeNode record = new TreeNode(primaryKey); records[i] = record; record.setAttribute("nameField", searchCriteria + parentThing.name); record.setAttribute("primaryKey", searchCriteria + primaryKey); record.setAttribute("parentId", (String) null); ++i; } response.setData(records); } processResponse(requestId, response); } } } int callCount = 0; private TreeGrid treeGrid; public SmartGWTTest() { FlowPanel mainPanel = new FlowPanel(); setHeight("100%"); setWidth("100%"); treeGrid = new TreeGrid(); treeGrid.setLoadDataOnDemand(true); final MyDataSource dataSource = new MyDataSource(); treeGrid.setDataSource(dataSource); treeGrid.setAutoFetchData(true); treeGrid.setFields(new TreeGridField("nameField", "Name")); treeGrid.setWidth100(); treeGrid.setHeight100(); treeGrid.draw(); Button btn = new Button("Click me to refresh"); btn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Criteria criteria = new Criteria(); criteria.setAttribute("searchCriteria", ++callCount); treeGrid.fetchData(criteria); } }); mainPanel.add(btn); mainPanel.add(treeGrid); add(mainPanel); } }
Comment