【问题标题】:Primefaces p:tree when loaded dynamicallyPrimefaces p:动态加载时的树
【发布时间】:2013-03-23 04:12:03
【问题描述】:

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

注意: 或者它不起作用。仅当 index.xhtml 中的 tabview 的 dynamic="true" 和 cache="false" 时才会出现问题。完整的代码如下,场景很容易重现。

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

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);
   }
}

【问题讨论】:

  • 浏览器中是否检测到任何javascript错误?
  • 不,正如我在请求处理期间以及尝试扩展时在 firebug 中注意到的那样。

标签: primefaces


【解决方案1】:

找到了解决方案。这很简单,但很困难。删除 one.xhtml 中的 &lt;h:head&gt;&lt;/h:head&gt; 标记,这不是必需的,并且正在重新加载已加载且非常可用的所需 js 文件。只需在主页中始终保留&lt;h:head&gt;&lt;/h:head&gt; 标签。这是 index.xhtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-16
    • 2014-06-11
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    相关资源
    最近更新 更多