How can I bid tree2 component?
Hi,
How can I bind my tomahawk tree2 in the bean, I have a tree in a panelGrid
and I want to expand and collapse the tree on click of a command button but
I dont want to use HtmlTree tree = (HtmlTree)pGrid.findComponent("clientTree"); since I want it to be reusable.
I tried binding it but that didnt work.
Can anyone suggest any idea please?
Thanks,
Sanjeev.
# 4
THis is my jsp:
<t:tree2 id="clientTree" binding="#{LibraryTreeModel.tree}" value="#{LibraryTreeModel.treeData}"
var="node" varNodeToggler="t" showRootNode="false"
clientSideToggle="true" preserveToggle="false">
<f:facet name="folder">
<h:panelGroup>
<f:facet name="expand">
<t:graphicImage value="images/obook.gif" rendered="#{t.nodeExpanded}" border="0"/>
</f:facet>
<f:facet name="collapse">
<t:graphicImage value="images/cbook.gif" rendered="#{!t.nodeExpanded}" border="0"/>
</f:facet>
<h:commandLink action="nodeClicked"
styleClass="#{t.nodeSelected ? 'documentSelected':'document'}"
actionListener="#{LibraryTreeHandler.processAction}"
immediate="true">
<h:outputText value="#{node.description}"/>
</h:commandLink>
</h:panelGroup>
</f:facet>
<f:facet name="document">
<h:panelGroup>
<t:graphicImage value="images/topic.gif" border="0"/>
<h:commandLink action="nodeClicked"
styleClass="#{t.nodeSelected ? 'documentSelected':'document'}"
actionListener="#{LibraryTreeHandler.processAction}"
immediate="true">
<h:outputText value="#{node.description}"/>
</h:commandLink>
</h:panelGroup>
</f:facet>
</t:tree2>
And this is the class having a method which returns the data model:
public class LibraryTreeModel {
private TreeNode treeData;
private HtmlTree tree;
.......
.......
public HtmlTree getTree() {
return tree;
}
/**
* @param tree The tree to set.
*/
public void setTree(HtmlTree tree) {
this.tree = tree;
}
ANd this is the class which handles tree events;
public class LibraryHandler {
private LibraryTreeModel treeModel;
public LibraryHandler() {
treeModel = new LibraryTreeModel();
}
public LibraryTreeModel getTreeModel() {
return treeModel;
}
public void expandAll(ActionEvent event) throws AbortProcessingException {
UIComponent component = (UIComponent)event.getSource();
HtmlTree tree = getTreeModel().getTree();
tree.expandAll();
}
public void processAction(ActionEvent event) throws AbortProcessingException {
UIComponent component = (UIComponent)event.getSource();
while (!(component != null && component instanceof HtmlTree)) {
component = component.getParent();
}
if (component != null) {
HtmlTree tree = (HtmlTree)component;
tree.setNodeSelected(event);
authorBio = tree.getNode().getIdentifier()+" "+tree.getNode().getDescription();
}
}
The processAction method just works fine, but expandAll() doesn't work.
Can u please look into this?
Thnx.