dynamic tree selected node property id issue...

hi -

I'm successfully building a two-tier tree dynamically, but when a node is selected, it isn't consistently giving the correct property id for that node... sometimes it's correct, sometimes it's null, sometimes I have to select the node twice to get a value, or it shows the value from the previous selected node...

I've tried tree1.getSelected() and tree1.getCookieSelectedTreeNode() but it's still the same result... it acts as though the cookie isn't getting updated each time... I've tried it with and without setting 'immediate' with the same result... below is the relevant part of my code... does anyone see why it's not getting the selected property id each time? help and suggestions welcome... Thanks

try {

java.util.List newNodeChildren = newNode.getChildren();

while (srs.next()){

TreeNode newNode2 = new TreeNode();

newNode2.setTarget("_blank");

newNode2.setText(srs.getString( "issue_title"));

newNode2.setId("x" + issue_id);

//Setup action event

Hyperlink nodelink = new Hyperlink();

nodelink.setText(newNode2.getText());

nodelink.setId(newNode2.getId());

Class[] signatures = {ActionEvent.class};

MethodBinding mb1 = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{Page2 .treeNodeActionListener}", signatures);

nodelink.setActionListener(mb1);

newNode2.getFacets().put(newNode2.CONTENT_FACET_KEY, nodelink);

newNodeChildren.add(newNode2);

}

srs.release();

} catch(SQLException ex) {

/error("SQL Error StatusTree Retrieval: " + ex);

}

}

public void treeNodeActionListener(ActionEvent event) {

String id = tree1.getCookieSelectedTreeNode();

String actualId = id.substring(id.lastIndexOf(":")+2);

info("treeNodeActionListener actualId = " + actualId);

}

[1899 byte] By [yukhntr] at [2007-11-26 9:06:14]
# 1
I have a similar problem when I try to use a dynamic tree in a master detail relation on a single page.String id = tree1.getCookieSelectedTreeNode(); return the id of the previous selected node.Anything doing?
OfPo at 2007-7-6 23:19:16 > top of Java-index,Development Tools,Java Tools...
# 2

IT WORKS!

But not with nodelink, apply directly to node:

Class[] signatures = {ActionEvent.class};

MethodBinding mb1 = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{Page2 .treeNodeActionListener}", signatures);

newNode2.setActionListener(mb1);

OfPo at 2007-7-6 23:19:16 > top of Java-index,Development Tools,Java Tools...
# 3

hi -

thanks for your replies... I've applied it to the node directly as you suggested, but for me it is now not calling the treeNodeActionListener method I had setup in my code... do I need to change something else? it only calls it when I change it *back* to apply it to nodelink...

ideas?

thanks

yukhntr at 2007-7-6 23:19:16 > top of Java-index,Development Tools,Java Tools...
# 4

but what you described is true... the getCookieSelectedTreeNode();

returns the id of the previous selected node... why? does no one else have this problem with it returning the previous selected node? odd behavior and very confusing.... I can't go forward without resolution of this problem...

yukhntr at 2007-7-6 23:19:16 > top of Java-index,Development Tools,Java Tools...
# 5

Hi,

1 I dropped Tree component from Palette. I deleted TreeNode1.

<ui:tree binding="#{Navigator.tree1}" expandOnSelect="false" id="tree1" immediate="true" style="left: 0px; top: 0px; position: absolute" text="Sometext"/>

2 In the init() method I called paintTree()

It works fine.

I use action method because I need only the id of selected node but I tested also listener method and it works

Here is my code

public void paintTree(){

....

ArrayList conturi=new ArrayList();

....

TreeNode nodN1 = new TreeNode();

TreeNode nodN2 = new TreeNode();

TreeNode nodN3 = new TreeNode();

....

TreeNode nodN9 = new TreeNode();

String Id;

int lga=0;

int lgc=0;

try {

conturi=getSessionBean1().getSes01FacadeRemoteClient1().getMyEjbMethod();

} catch (Exception ex) {

log(".....", ex);

}

Iterator iterator=conturi.iterator();

while (iterator.hasNext()) {

detalii.Conturi cont=(detalii.Conturi)iterator.next();

lgc=cont.getConts().length();

if (lga < lgc) {

if (lgc == 1) {

nodN1=new TreeNode();

Id= "Node_"+cont.getId();

nodN1.setId(Id);

nodN1.setText(cont.getDenumire());

tree1.getChildren().add(nodN1);

}

if (lgc == 2){

nodN2=new TreeNode();

Id= "Node_"+cont.getId();

nodN2.setId(Id);

nodN2.setText(cont.getConts()+"-"+cont.getDenumire());

nodN2.setStyleClass("leftAligned");

nodN1.getChildren().add(nodN2);

}

if (lgc == 3){

nodN3=new TreeNode();

Id= "Node_"+cont.getId();

nodN3.setId(Id);

nodN3.setText(cont.getConts());

nodN3.setStyleClass("leftAligned");

FacesContext context=FacesContext.getCurrentInstance();

MethodBinding mb1 = context.getApplication().createMethodBinding("#{Navigator.treeNode_action}", null);

nodN3.setAction(mb1);

nodN2.getChildren().add(nodN3);

}

....

} //end-if

} //end while

....

}

public String treeNode_action() {

....

try {

clientId=tree1.getCookieSelectedTreeNode();

String id =clientId.substring(clientId.lastIndexOf("_")+1);

getSessionBean1().setContId(id);

....

info("clientId = "+ clientId);

} catch (Exception ex) {

log("Error Description", ex);

}

return null;

}

OfPo at 2007-7-6 23:19:16 > top of Java-index,Development Tools,Java Tools...