我在Primefaces新的,我嘗試使用現在的Primefaces樹了好幾天。 基本上,我有一棵樹。我附加到這棵樹的上下文菜單。當我點擊上下文菜單時,會打開一個對話窗口並顯示有關樹的選定節點的更多詳細信息。我嘗試重現基於Tree和TreeTable示例的primefaces展示。Primefaces 3.4:樹selectedNode是空
當我跑我的項目,我嘗試打開對話窗口,我有這樣的錯誤在調試器:
WARNING: /protected/treeonly.xhtml @34,91 value="#{folderManagedBean.selectedNode.data.name}": Target Unreachable, 'null' returned null
javax.el.PropertyNotFoundException: /protected/treeonly.xhtml @34,91 value="#{folderManagedBean.selectedNode.data.name}": Target Unreachable, 'null' returned null
請看以下JSF頁面
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form id="form">
<!--*********** Context Menu ***********-->
<p:contextMenu for="folderTree">
<p:menuitem value="Rename Folder" update="folderPanel" oncomplete="folderDialog.show();" icon="ui-icon-plus"/>
</p:contextMenu>
<!--*********** Folder Tree ***********-->
<p:tree style="border:none;" id="folderTree" value="#{folderManagedBean.root}" var="folder" selectionMode="single" selection="#{folderManagedBean.selectedNode}">
<p:treeNode expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{folder.name}" />
</p:treeNode>
</p:tree>
<!--*********** Dialog Box ***********-->
<p:dialog header="New Folder" widgetVar="folderDialog" modal="true" resizable="false"
showEffect="clip" hideEffect="fold">
<p:outputPanel id="folderPanel">
<h:panelGrid columns="2" cellpadding="4">
<h:outputText value="Folder Name:" />
<p:inputText value="#{folderManagedBean.selectedNode.data.name}"/>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</h:body>
</html>
這裏託管bean :
@ManagedBean
@SessionScoped
public class FolderManagedBean implements Serializable{
@EJB
private FolderBean folderBean;
private Folder froot;
private TreeNode root;
private TreeNode selectedNode;
public FolderManagedBean() {
}
@PostConstruct
public void initialize(){
root = buildTree();
}
public TreeNode getRoot(){
return root;
}
private TreeNode buildTree(){
froot = folderBean.getRootFolder();
root = new DefaultTreeNode("root", null);
TreeNode realRoot = new DefaultTreeNode(froot, root);
for (Folder child : froot.getChildFolders()){
TreeNode tnChild = new DefaultTreeNode(child, realRoot);
tnChild.setParent(realRoot);
buildTreeRecursively(tnChild);
}
return root;
}
private void buildTreeRecursively(TreeNode currentNode){
Folder folder = (Folder)(currentNode.getData());
for(Folder child : folder.getChildFolders()){
TreeNode tnChild = new DefaultTreeNode(child, currentNode);
tnChild.setParent(currentNode);
buildTreeRecursively(tnChild);
}
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
}
任何幫助將非常感激。
請不要發佈**的**所有代碼。只發布相關部分,不相關部分影響可讀性,根本沒有幫助。 – siebz0r
你當然是對的。但是我在尋找這麼多天的解決方案,以至於我不知道什麼是相關或不相關的。謝謝你的評論。 –