voyent
How do I determine selected node in ice:tree from Backing bean  XML
Forum Index -> Components
Author Message
grahams

Joined: 26/May/2006 00:00:00
Messages: 27
Offline


I have an ice:tree component and when a node is selected by clicking on it I want to change the content in another area of the screen based on which Node was clicked.

Looking at your example you pass a reference to the backing bean into each node of the tree and then use an action method on the node to update the backing bean. I can't use this method as my Tree Model will have application scope and be used by many backing beans.

When using a standard h:datatable populated with content wrapped in a javax.faces.model.DataModel you can query the Model object and determine the selected row.

Is there any way to perform equivalent functionality when using an ice:tree component?

Thanks.

Graham.
gregory_m

Joined: 17/Jan/2005 00:00:00
Messages: 130
Offline


It sounds like you want to use the tree as a navigation component. Our component-showcase demo uses the tree in this way. We have included the source for the component-showcase in the latest community edition of ICEfaces.

The source can be found in the following location.

\ICEfaces-Community-1.0.0\src\component-showcase

Please take alook at the source and in the mean time I will take a closer look at your question and get back to you with a better answer.

Thanks,
-- Greg McCleary --
grahams

Joined: 26/May/2006 00:00:00
Messages: 27
Offline


Thanks for the prompt response. I am actually using the tree to represent a linguistic taxonomy (genuniely tree stuctured data) When the user clicks on a node in the taxonomy I want to display details in another pane on the screen.

I have found a workaround to the problem (found by browsing this forum). I am using an f:param in the commandlink but I have another problem.

I click on one node in the Tree and my backing bean method is called, I click on other nodes and it is not. If I click one of the expand/contract icons to show/hide sections of the tree, then click on a node my backing bean is called again, then subsequent clicks do not call it until I expand/contract another node.

Additional testing shows that the backing bean is called about 20% of the time if I haven't just expanded/contracted a node and 100% of the time if I have.

Here is the relevant part of the jspx page:

<ice:tree id="tree" value="#{nodeHandler.treeModel}"
hideRootNode="false" hideNavigation="false" var="item">
<ice:treeNode id="taxTree">
<f:facet name="icon">
<ice:panelGroup style="display: inline" rendered="#{item.leaf}">
<h:graphicImage value="Images/leaf2.gif"/>
</ice:panelGroup>
</f:facet>
<f:facet name="content">
<ice:panelGroup style="display: inline">
<ice:commandLink partialSubmit="true" action="#{nodeHandler.selectNode}">
<ice:outputText value="#{item.userObject.text}" styleClass="parafont" style="" rendered="#{not (item.userObject.nodeId == nodeHandler.selNode)}"/>
<ice:outputText value="#{item.userObject.text}" styleClass="parafont" style="font-weight: bold" rendered="#{item.userObject.nodeId == nodeHandler.selNode}"/>
<f:param name="nodeId" value="#{item.userObject.nodeIdString}">
</f:param>
</ice:commandLink>
<ice:outputText value="(#{(item.userObject.docCount >= 0) ? item.userObject.docCount : '??'})" styleClass="parafont" rendered="#{not item.userObject.treeRoot}"/>
</ice:panelGroup>
</f:facet>
</ice:treeNode>
</ice:tree>

and the method in the backing bean:

public String selectNode() {
System.out.println("select Node Called");
FacesContext c = FacesContext.getCurrentInstance();
Map requestParams = c.getExternalContext().getRequestParameterMap();
int id = Integer.parseInt((String)requestParams.get("nodeId"));
System.out.println("got ids : " + id);
selNode = id;
return "success";
}

Any ideas?

Graham.

P.S. Apologies for the multiple posts but my session timed out composing the message and that was the result.
grahams

Joined: 26/May/2006 00:00:00
Messages: 27
Offline


The chunk of jspx didn't display correctly. I have attached it to this message
 Filename icefaceschunk.txt [Disk] Download
 Description No description given
 Filesize 1 Kbytes
 Downloaded:  391 time(s)

grahams

Joined: 26/May/2006 00:00:00
Messages: 27
Offline


I have further information.

When you click on the node in the tree it populates another pane on the screen. This pane contains a text input box and a datatable where each line contains a text input box.

I have two issues. Firstly some of the data used to populate the text input boxes in the table contains quotation marks, in such cases the Direct-to-DOM Renderer shows these boxes as blank, I have to escape the quotations marks to " inside the Bean being used to populate the table to get the desired output. I don't believe this is the case in the regular HTML renderer.

The second issue is more insidious. The content of the input text box is consistently updated each time a node in the tree is successfully selected. However, this is not the case for the contents of the table. Everything works fine up to the point where I click on a node and the backing bean isn't called (see above) after this point even if I click a node and the backing been is called, only the stand alone text input box is updated, the table stays as it was.

From my simple debugging, I am correctly updating the DataModel that fills the table, it appears that the Direct-to-DOM renderer is no longer noticing that the backing bean data is changing and is not updating the browser DOM.
gregory_m

Joined: 17/Jan/2005 00:00:00
Messages: 130
Offline


Thanks for the code. No ideas yet. I am working on a test case using your code snippets.
I have not tried to use the tree with an action listener that is not defined in the Node (IceUserObject). I'll give it a try and I'll post when I find a solution.

-- Greg McCleary --
grahams

Joined: 26/May/2006 00:00:00
Messages: 27
Offline


I have been working to generate a simple application that recreates the problem and have discovered the cause.

The problem was casued becasue I had an ice:hidden tag on the page that had a value bound to the selNode property of the NodeHandler bean. That same value is updated when you click one of the links. I guess this is causing some sort of clash. Fortunately, the ice:hidden tag was no longer necessary and was in fact a remnant of when this was a non ICEfaces app and I had to do my own Javascript/Ajax code. Removing the tag solved the problem. I have though attached a WAR file that demonstrates the problem. If you click nodes in the tree then the selection only 'takes' some of the time.
 Filename TreeProblem.war [Disk] Download
 Description No description given
 Filesize 4174 Kbytes
 Downloaded:  318 time(s)

gregory_m

Joined: 17/Jan/2005 00:00:00
Messages: 130
Offline


I am glad to hear that you found a solution to the problem you were having with the ice:tree component.

I have deployed and run your test app and confirmed your observation.

After removing the ice:inputHidden the test app worked fine.

I believe the ice:inputHidden was conflicting with the hidden fields that are rendered by the icefaces commandLink renderer. When you inspect the page source in your browser you will notice that all commandLinks have an associated hidden input field (command_link_hidden_field).

A tool like FireFox:FireBug is very handy for dynamically inspecting your icefaces pages.

Firebug addon download -> https://addons.mozilla.org/firefox/1843/

Thanks for your feedback.

-- Greg McCleary --
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team