我使用PrimeFaces 2.2.1 Tree組件在Glassfish 3.1PrimeFaces樹選擇空
我試圖在樹中選擇的節點設置爲我支持bean一個TreeNode對象,但它始終是零。
我問PrimeFaces論壇的支持,但不幸收到了沒有答覆。
<p:tree id="contextTree" value="#{contextTreeBean.contextRoot}" var="node" selectionMode="single" selection="#{contextTreeBean.selectedNode}">
<p:treeNode>
<h:outputText value="#{node.name}"/>
</p:treeNode>
</p:tree>
<h:outputText id="output" value="#{contextTreeBean.output}"/>
<p:commandButton id ="createButton" value="+" actionListener="#{contextTreeBean.createContext()}" update="contextTree, output"/>
@ManagedBean
@RequestScoped
public class contextTreeBean {
@EJB
private ContextFacadeLocal contextFacade;
private Context context = new Context();
private TreeNode contextRoot;
private TreeNode selectedNode;
private String output;
/** Creates a new instance of contextTreeBean */
public contextTreeBean() {
}
public void createContext() {
output = selectedNode.getData().toString();
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
public ContextFacadeLocal getContextFacade() {
return contextFacade;
}
public void setContextFacade(ContextFacadeLocal contextFacade) {
this.contextFacade = contextFacade;
}
public TreeNode getContextRoot() {
return contextRoot;
}
public void setContextRoot(TreeNode contextRoot) {
this.contextRoot = contextRoot;
}
@PostConstruct
private void postConstruct() {
populateContextTree();
}
private void populateContextTree() {
buildContextTree(new DefaultTreeNode("Root", null), contextFacade.findRootContexts());
}
private void buildContextTree(TreeNode parentNode, List<Context> children) {
for (Context currentContextNode : children) {
TreeNode tempNode = new DefaultTreeNode(currentContextNode, parentNode);
buildContextTree(tempNode, currentContextNode.getChildren());
}
contextRoot = parentNode;
}
}
如果您更改bean以查看作用域或會話作用域,它會工作嗎? – 2011-06-15 10:55:52