collapsing p:tree
I have a tree that is used as menu, so every node is clickable and opens another *.xhtml file. The tree is displayed on every *.xhtml file with templates.
Problem: the tree collapses if redirect to a *.xhtml file. Surprisingly, the selected node stays selected (it is colored as selected). The tree shouldn't collapse!
The tree is generated dynamic, but it is only generated once.
Tested with Primefaces 2.2.1 and 3.0.M2
How can I solve this problem? At primefaces showcase this works.
My code:
<h:form id="formTreeStudents">
<p:tree id="treeGroups"
value="#{studentTree.root}"
var="node"
cache="true"
selectionMode="single"
nodeSelectListener="#{studentTree.onNodeSelect}"
selection="#{studentrTree.selectedNode}"
onselectComplete="ajaxDialog.show();"
update="statusbar userbar">
<p:treeNode>
<h:outputText value="#{node.treeString}" styleClass="treeNodeParent"/>
</p:treeNode>
</p:tree>
<p:ajax event="load" onstart="ajaxDialog.hide();"/&g开发者_开发问答t;
</h:form>
The bakingBean is sessionScoped. It has getter and setter similar to the example at primefaces showcase and a listener function.
@ManagedBean
@SessionScoped
public class StudentTree implements Serializable{
...
public void onNodeSelect(NodeSelectEvent event) {
...
}
}
The tree node stays selected because the property #{studentrTree.selectedNode}
of the managed bean has a value.
Your managed bean is @SessionScoped
so it will live in session even after you navigate away from and back to the page. If you were to change it to @ViewScoped
then the managed bean will die when navigating away from the page, and when you navigate back to the page the property selectedNode
will be its default value again.
solved it.
it works with Primefaces 3.0.M2. Something was wrong with my libraries or with cached data. Some changes had to be done to use 3.0.M2.
f.e.:
nodeSelectListener="#{studentTree.onNodeSelect}"
is now replaced with
<p:ajax event="select" listener="#{studentTree.onNodeSelect}"/>
精彩评论