I'm experimenting using a navigation tree with a <p:layout /> and an <ui:include />, which I want to dynamically update the <ui:include /> when I click on a tree node.
The backing bean
Code: Select all
@SessionScoped
public class MenuTreeBean implements Serializable
{
private static final long serialVersionUID = -1L;
private final TreeNode root;
private TreeNode selectedNode;
public MenuTreeBean()
{
root = new DefaultTreeNode("root", null);
CustomTreeNode aaRoot = new CustomTreeNode("welcome", "Widgets", root);
new CustomTreeNode("1", "Editor", aaRoot);
new CustomTreeNode("2", "Calendar", aaRoot);
setSelectedNode(aaRoot);
}
public TreeNode getMenuTree()
{
return root;
}
public TreeNode getSelectedNode()
{
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode)
{
this.selectedNode = selectedNode;
this.selectedNode.setSelected(true);
}
public void onTreeNodeClicked(NodeSelectEvent e)
{
setSelectedNode(e.getTreeNode());
}
}
Code: Select all
public class CustomTreeNode extends DefaultTreeNode
{
private String name;
public CustomTreeNode(String name, Object value, TreeNode parent)
{
super(value, parent);
this.name = name;
}
public String getName()
{
return name;
}
}
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="left" width="200" resizable="true" collapsible="true">
<h:form>
<p:tree expanded="true" nodeSelectListener="#{menutree.onTreeNodeClicked}" id="tree"
value="#{menutree.menuTree}" var="node" update="test,tree"
selection="#{menutree.selectedNode}" selectionMode="single">
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" resizable="true" collapsible="false">
<h:panelGroup id="test" layout="block">
<ui:include src="${menutree.selectedNode.name}.xhtml" />
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
The problem I have is
- when I click on the Editor node above, it gets selected and highlighted, and the <ui:include /> loads the page/chunk I requested
- when I click on the Calendar node above, it gets selected and highlighted, and the <ui:include /> loads the page/chunk I requested
- when I click back on the Editor node above, it did not get selected, but the <ui:include /> still loads the page/chunk I requested; the Calendar node was still highlighted
If I turn off the update attribute at <p:tree />, tree node selection and highlight is working as expected; except I miss the dynamic <ui:include /> which I needed.
I wonder if I missed anything? TIA.
Environment: OpenJDK 6.0, Primefaces 2.2 + Aristo theme, Mojarra 2.1.1-b04, Maven2 jetty-maven-plugin 7.4.0.v20110414 and Firefox 4
edit: CustomTreeNode