You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2006/03/02 16:56:54 UTC
TreeNodeChecked and t:treeCheckbox sample ?
Hi all,
Could anybody tell me how to use the t:treeCheckbox tag?
Can I use this tag with the tree2 component?
I have a TreeNode (serverSideToggle) with many nodes and I used the
nightly TreeNodeChecked class to add checkboxes before my leaf nodes.
This is working fine so far.
But I have to process the whole tree in my Listeners to find the
selected nodes.
Is it possible to store the selected checkboxes of a tree2 in a String[]
or a similar container?
This would simplify or improve my backend processing.
Below are code snippets:
Thanks for any comments or help
Michael
<t:tree2 id="serverTree"
value="#{SearchControllerBean.treeController.treeData}"
var="node"
varNodeToggler="t"
clientSideToggle="false"
showRootNode="true">
<f:facet name="document">
<h:panelGroup>
<h:selectBooleanCheckbox value="#{node.checked}"/>
<h:commandLink immediate="true" styleClass="#{t.nodeSelected
? 'documentSelected':'document'}" actionListener="#{t.setNodeSelected}">
<h:outputText value="#{node.description}"/>
<f:param name="docNum" value="#{node.identifier}"/>
</h:commandLink>
</h:panelGroup>
</f:facet>
</t:tree2>
TreeController is just a copied TreeBacker from MyFaces samples.
public class TreeController implements Serializable {
private TreeModelBase _treeModel;
private HtmlTree _tree;
private String _nodePath;
TreeNode treeData;
public TreeController(){
//dummy initialization: do this not in the constructor!
treeData = new TreeNodeBase("root-folder", "All", false);
TreeNodeBase catNode = new TreeNodeBase("categories", "folder1",
false);
catNode.getChildren().add(new TreeNodeChecked("document", "doc1,
true, true));
catNode.getChildren().add(new TreeNodeChecked("document",
"doc2", true));
catNode.getChildren().add(new TreeNodeChecked("document",
"doc3", true));
catNode.getChildren().add(new TreeNodeChecked("document",
"doc4", true));
treeData.getChildren().add(catNode);
catNode = new TreeNodeBase("categories", "folder2", false);
catNode.getChildren().add(new TreeNodeChecked("document",
"doc5", true));
catNode.getChildren().add(new TreeNodeChecked("document",
"doc6", true));
treeData.getChildren().add(catNode);
}
public TreeNode getTreeData(){
return treeData;
}
public TreeModel getExpandedTreeData(){
return new TreeModelBase(getTreeData());
}
public void setTree(HtmlTree tree){
_tree = tree;
}
public HtmlTree getTree(){
return _tree;
}
public String expandAll(){
_tree.expandAll();
return null;
}
public void setNodePath(String nodePath){
_nodePath = nodePath;
}
public String getNodePath(){
return _nodePath;
}
public void checkPath(FacesContext context, UIComponent component,
Object value){
FacesMessage message = null;
String path[] = _tree.getPathInformation(value.toString());
for(int i = 0; i < path.length; i++){
String nodeId = path[i];
try{
_tree.setNodeId(nodeId);
}
catch(Exception e){
throw new ValidatorException(message, e);
}
if(_tree.getNode().isLeaf()){
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Invalid node path (cannot expand a leaf): " + nodeId, "Invalid node
path (cannot expand a leaf): " + nodeId);
throw new ValidatorException(message);
}
}
}
public void expandPath(ActionEvent event) {
_tree.expandPath(_tree.getPathInformation(_nodePath));
}
}