lilleGauss
lilleGauss

Reputation: 68

Why does the ajax event not fire?

I've got a primeface tree in my application. I tried to load all data att once it it jsut to much 2500 object, only some are used. So I tried to implement som sort of lazy loading. The first level is loaded on start and I would like to load the neccessary data when expanding the node. I googled some examples and modified it for my purpose. But in my case the ajax does not fire. what am i missing here?

the xhtml part

<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>

Before loading the first level of tree is build by

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

 }

which works fine. The ajax event should trigger this but it don't happen.

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

Any idea why?

Best regards Ralf

using tomcat 7.0.52 JSf 2.2 and primefaces 4.0

Upvotes: 2

Views: 134

Answers (1)

wittakarn
wittakarn

Reputation: 3164

Due to you did not set attribute 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>

Upvotes: 1

Related Questions