我是 Primefaces 的新手,我现在尝试使用 Primefaces 树好几天了。基本上,我有一棵树。我在这棵树上附加了一个上下文菜单。当我单击上下文菜单时,会打开一个对话窗口并显示有关树的选定节点的更多详细信息。我尝试根据 Tree 和 TreeTable 示例重现 primefaces 展示。
当我运行我的项目时,我尝试打开对话框窗口,我在调试器中有这个错误:
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;
}
}
任何帮助将非常感激。