Primefaces p:动态加载时的树

时间:2013-03-23 04:12:03

标签: primefaces

我在xhtml中使用p:tree,它动态包含在另一个xhtml的tabview中。当我们更改标签时,树扩展不起作用。我无法通过单击节点旁边的图标来展开树。

注意:或者它不起作用。只有当index.xhtml中的tabview的dynamic =“true”和cache =“false”时才会出现问题。完整的代码如下所示,方案很容易重现。

由于我在项目的许多地方使用p:tree,我请求任何人提供至少一个临时解决方法,如果这是一个错误。我已经在primefaces论坛上发布了这个。我在Tomcat 7.0上使用Primefaces 3.5和JSF

的index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:p="http://primefaces.org/ui">
   <h:head></h:head>
   <h:body>
      <p:tabView dynamic="true" cache="false">
         <p:tab title="One">
            <ui:include src="/one.xhtml" />
         </p:tab>
         <p:tab title="two" />
      </p:tabView>
   </h:body>
</html>

one.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:p="http://primefaces.org/ui">
   <h:head>
   </h:head>
   <h:body>
       <p:tree widgetVar="treeStructure" value="#{treeBean.root}" var="node" selectionMode="single" id="tree">
           <p:treeNode>
               <h:outputText value="#{node}" />
           </p:treeNode>
       </p:tree>
   </h:body>
</html>

TreeBean.java

@ManagedBean
@SessionScoped
public class TreeBean {
   private TreeNode root;

   public TreeNode getRoot() {
      return root;
   }
   public void setRoot(TreeNode root) {
      this.root = root;
   }
   public TreeBean() {
      root = new DefaultTreeNode("Root", null);
      TreeNode node0 = new DefaultTreeNode("Node 0", root);
      TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);
   }
}

1 个答案:

答案 0 :(得分:0)

找到解决方案。这虽然简单明了但很挣扎。删除 one.xhtml 中的<h:head></h:head>标记,这是不必要的,并且正在重新加载已加载且非常可用的所需js文件。只需在主页中保留<h:head></h:head>标记即可。这是 index.xhtml