Need help with TreeGrid

I am new to SmartClient, I am tring to use SmartClient’s TreeGrid component. I am setting a list of java objects in dsResponse . The list got all objects. But I am getting an error as
" “rootValue” is null or not an object ". What I am doing wrong? am I missing anything in the code?

Thanks in advance.

DataSource.create({
ID:“bomData”,
parentID: “parentPartNo”,
fields:{
Id:{name:“id”,type:“text”,title:“ID”, length:128, primaryKey:true},
ParentPartNo:{name:“parentPartNo”,type:“text”, title:“Parent Part No”, primaryKey:true},
PartNo:{name:“name” ,type:“text” , title:“Part No” }
});

isc.RPCManager.actionURL = “<c:url value=‘/frames/bomViewOperations.jsp?’/>”;
isc.TreeGrid.create({
ID:“boundNewList”,
width:900, height:300,
dataSource:bomData,
modelType:“parent”,
rootValue:“ParentPartNo”,
fields:[
{name:“Id”},
{name:“ParentPartNo”},
{name:“PartNo”}
]
});

--------------bomViewOperations.jsp-----
RPCManager rpc;
try {
rpc = new RPCManager(request, response, out);

} catch (ClientMustResubmitException e) {
return;
}

for(Iterator i = rpc.getRequests().iterator(); i.hasNext():wink: {
Object req = i.next();
if(req instanceof RPCRequest)
throw new Exception(“This example expects only DSRequests”);
DSRequest dsRequest = (DSRequest)req;
String dsName = dsRequest.getDataSourceName();
if(!“bomData”.equals(dsName)) {
rpc.send(dsRequest, dsRequest.execute());
continue;
}
DataSource bomData = dsRequest.getDataSource();

DSResponse dsResponse = new DSResponse();

dsResponse.setSuccess();

String operation = dsRequest.getOperationType(); 

if(operation.equals(DataSource.OP_FETCH)) {
    HttpSession sess = request.getSession(false) ;
    ServletContext context = sess.getServletContext();
    String id = request.getParameter("id");
                    id = "2"; 
                    String bomName = request.getParameter("BomName");
                    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext (context);
                    ImportedBomManager mgr = (ImportedBomManager) ctx.getBean("importedBomManager"); 
                    ImportedBom bom = null;
                    if (id != null)
                                bom = mgr.getImportedBom(id);
                    else if (bomName != null)
                    {
                                bom = new ImportedBom();
                                bom.setName(bomName);
                                List boms = mgr.getImportedBoms(bom);
                                if (boms.size() &gt; 0)
                                {
                                            bom = (ImportedBom) boms.get(0);
                                            id = bom.getId().toString();
                                }
                    }
                    String partNo = bom.getPartNo();
                    if (partNo == null || partNo.length() == 0)
                                return;

// Once everything works fine change "partNo" to 
//String parentID = (String)dsRequest.getCriteria().get("parentID");
   dsResponse.setData(getChildren(bom,partNo,ctx));
} 
        else {
    throw new Exception("Operation: " + operation + " not implemented."); 
}
// match the response to the request

rpc.send(dsRequest, dsResponse);

}

Hi sanlemo,

You haven’t declared the tree relationship within your DataSource. You need to add foreignKey:“PartNo” to the “ParentPartNo” field. This tells SmartClient that the tree structure is formed by linking “ParentPartNo” values with “PartNo” values to find parents. For more information, see the tree databinding overview.

Actually, there are a couple of other problems too.

  1. You’ve set dataSource.parentID, but this property doesn’t exist.

  2. It looks like you’re using a DataSource derived from XML, but you’ve hand-edited it in JavaScript, and now the field names do not match (eg the field “PartNo” has name “name” instead of “PartNo”). If you are going to maintain your DataSource in JavaScript from now on, fields should be specified as an Array, as shown in this RSS feed example.

Thank you, It worked. Now I have a different issue.

I retrive 2 levels of data from server(out of multiple levels). It displays “closed icon” for all first level node valuses. User has to click on every node value to see if it got childern or not. But I want to have the “Closed Icon” to only those values which are having childern.

Can you please tell me what propery i should use.

Note: Since the tree got huge data, I can not bring entire data from server on its initial fetch.

Hi sanlemo,

To specify that a node has no children you can explicitly return an empty child list. This is shown with XML data here (note the empty <directReports></directReports> elements):

http://www.smartclient.com/#_Trees_Data.binding_Load.XML

If you are using the SmartClient server, you can place an empty ArrayList under the childrenProperty of the returned nodes.

If what you want is actually to specify that a node cannot have children, you can instead set the node’s isFolder property to false.

Hi,

I used isFolder property for nodes and it worked.

Thank you,