Selected row in tree

Hello All,
I have one tree with structure like…
–root
----------child level1
-----------------child level2
-------------------------Element 1
-------------------------Element 2
-------------------------Element 3
-------------------------Element 4

And I have row selected check box for selecting row.
Now with click on one command button I want to retrieve selected row details.But not able to get achieve this.
I have code like this…
List a=dataTestProvider.getSelectedRows();
for(int i=0;i<a.size();i++)
{
Test g=(Test) a.get(i);//Test is the Object for row class
System.out.println(“name:”+g.getName());
}

But always I am getting error as Can’t be converted to this class.

Is there any alternative way to read the rows of selected rows in tree…because same code is working in table structure.
And also working for List a=dataTestProvider.getList(); instead of getSelectedRows();

Thanks
Baharul

A couple of questions to refine the problem:

  1. Which tree provider class are you using for your use case?

  2. What type of Object are you getting in the selected rows list?

Below are some details

private com.webMethods.caf.faces.data.tree.object.NodeTreeContentProvider testProvider = null;

//Setting data provider as

public com.webMethods.caf.faces.data.tree.object.NodeTreeContentProvider getTestProvider() {

	testProvider= new BoundChildrenTreeContentProvider(getTest(),"test" , "#{test.customerId},#{test.orderId},#{test.widgetId}", "#{test.orders},#{test.widgets}");
    return testProvider;
}

Getting below error when trying to access class

com.webMethods.caf.faces.data.tree.object.BoundChildrenNode$PermissiveContentProviderWrapper cannot be cast to com.data.Customer

Version used is 8.2
Please find the attached work space for your reference…

treeExample10_Oct.zip (40.7 KB)

Ok. The BoundChildrenTreeContentProvider wraps your row objects with another object to adapt them to a format suitable for the tree.

You can retrieve the original object from the wrapper with something like this:

//the row is the wrapper object
BoundChildrenNode$PermissiveContentProviderWrapper wrapper = (BoundChildrenNode$PermissiveContentProviderWrapper)a.get(i);

//get the original object that was wrapped. 
Test g=(Test) wrapper.getObject();//Test is the Object for row class 

But BoundChildrenNode$PermissiveContentProviderWrapper is not getting to resolve to a type.

Is there any documentation available for this.

Thanks Eric for your reply.

This is get solved in some way.

PermissiveContentProviderWrapper wrapper=(PermissiveContentProviderWrapper) a.get(i);
Test g=(Test) wrapper.getObject();

Here I am able to get selected row details.

Now facing problem here is to add the selected row again to Tree/TreeProvider with some editted contents.

when trying to use methods treeProvider.createRow() …getting one error like
com.data.Customer cannot be cast to com.webMethods.caf.faces.data.tree.INode.