View Full Version : Treepanel : The grandparents of selected tree node is NULL

16 Dec 2011, 2:34 AM
I've a problem when I click on a node with depth 2, I can't recover its grandparents, there is null.

TreeStore<BeanModel> objStore = new TreeStore<BeanModel>();
TreePanel<BeanModel> objTree = new TreePanel<BeanModel>(objStore);

objTree.getSelectionModel().addListener(Events.BeforeSelect, new Listener<SelectionEvent<BeanModel>>() {

public void handleEvent(SelectionEvent<BeanModel> be) {
AgdRdvDTO selectAppointment = null;
AgdDemandeDTO selectDemande = null;
AgdSuiviDTO selectSuivi = null;

TreePanelSelectionModel<BeanModel> tree = (TreePanelSelectionModel<BeanModel>) be.getSource();
BeanModel item = be.getModel();
if (item.getBean() instanceof AgdDemandeDTO) {
selectDemande = item.getBean();
} else if (item.getBean() instanceof AgdSuiviDTO) {
selectSuivi = item.getBean();
selectDemande = objStore.getParent(item).getBean();
} else if (item.getBean() instanceof AgdRdvDTO) {
selectAppointment = item.getBean();

BeanModel beanSuivi = objStore.getParent(item);
selectSuivi = beanSuivi.getBean();
BeanModel grandParents= objStore.getParent(objStore.getParent(item));
if (grandParents!= null) {
selectDemande = grandParents.getBean();
AgendaEventBus.getEventBus().fireEvent(new SelectDetailEvent(selectDemande, selectSuivi, selectAppointment));

The first time I clicked, grandParents is initialized and if i clicked on an other item of the same parent, the grandParents is always null.

Thanks for your help

4 Jan 2012, 4:49 AM
You should try get the store reference everytime you need it. May be one update/load has changed it. Therefore your reference does not reflect what is actually in it.

tree.getStore() instead of using objStore

4 Jan 2012, 4:52 AM
I meant: