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]

# 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 >
