【问题标题】:Why does the ajax event not fire?为什么ajax事件不触发?
【发布时间】:2014-12-06 00:04:28
【问题描述】:

我的应用程序中有一个 primeface 树。我尝试将所有数据加载到 2500 个对象,但只使用了一些。所以我尝试实现某种延迟加载。第一级在启动时加载,我想在扩展节点时加载必要的数据。我搜索了一些示例并出于我的目的对其进行了修改。但在我的情况下,ajax 不会触发。我在这里错过了什么?

xhtml 部分

<h:form>
    <p:panel id="add_elev2list" 
             header="lägg till elev" 
             collapsed="true" 
             toggleable="true">
        <p:tree value="#{bookb.root}" 
                var="node" 
                dynamic="true"  >
            <p:ajax event="select" 
                    update="@this"  
                    listener="#{bookb.onNodeSelect}"/>
            <p:treeNode >
                <h:outputText value="#{node}"   />
            </p:treeNode>
        </p:tree>
    </p:panel>
</h:form>

在加载第一级树之前由

public void triggerTreeBuild() {
     root = new DefaultTreeNode("Root", null);
     ObjectContainer localdb = dbConnector.connDB();
        ObjectSet<sbasUserList> res;
        Query query = localdb.query();
        query.constrain(sbasUserList.class);
        //query.descend("klass").constrain(true);
        res = query.execute();
        for(sbasUserList sbu : res ){

             if(sbu.isKlass()) {
                 TreeNode node0 = new DefaultTreeNode(sbu.getGroupname(), root);
                 node0.getChildren().add(new DefaultTreeNode("head"));
                }
        }
        localdb.close();

 }

效果很好。 ajax 事件应该触发这个,但它不会发生。

public void onNodeSelect(NodeSelectEvent nee){
     log("expand"); //wrapper for System.out.println ... for some sort of debugging.
     sbasUserList sbu = (sbasUserList) nee.getTreeNode().getData();
     String[] allstd =  sbu.getAllusers().split(",");
     ObjectContainer localdb = dbConnector.connDB();
        for(String persnum : allstd){
            nee.getTreeNode().getChildren().add( new DefaultTreeNode(
                    getUserbyPersnum(localdb,persnum).getRealname())); 
        }
        localdb.close();
 }

知道为什么吗?

最好的问候 拉尔夫

使用 tomcat 7.0.52 JSf 2.2 和 primefaces 4.0

【问题讨论】:

    标签: ajax jsf-2 primefaces


    【解决方案1】:

    由于你没有设置属性selectionMode="single"

    <p:tree value="#{treeBasicView.root}" 
            var="node" 
            dynamic="true"  
            selectionMode="single">
        <p:ajax event="select" listener="#{treeBasicView.onNodeSelect}" />
        <p:treeNode>
            <h:outputText value="#{node}" />
        </p:treeNode>
    </p:tree>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多