0

On a JSF-Primefaces based liferay portlet (PrimeFaces 6.1), I'm trying to do custom tasks when a element is selected within a <p:tree>. To do so, I'm using PF ajax feature along with a listener method on my backing Bean, according to what the PF documentation states. The custom tree is displayed as expected but when I click on a <p:treeNode> element nothing happens.

xhtml side:

<h:form id="form">
        <p:growl id="messages" showDetail="true" />         
        <p:tree id="entityTree" value="#{bean.entityTree}" var="node" animate="true" selectionMode="single" selection="#{bean.selectedNode}">

            <p:ajax event="select" update=":form:messages" listener="#{bean.onNodeSelect}" />
            <p:ajax event="expand" update=":form:messages" listener="#{bean.onNodeExpand}" />
            <p:ajax event="collapse" update=":form:messages" listener="#{bean.onNodeCollapse}" />

            <p:treeNode>
                <h:outputText value="#{node}" />
            </p:treeNode>
            <p:treeNode type="type-0">
                <h:outputText value="#{node}" />
            </p:treeNode>
            <p:treeNode type="type-1">
                <h:outputText value="#{node}" />
            </p:treeNode>
        </p:tree>
</h:form>

Bean side:

@ManagedBean(name = "bean")
@ViewScoped
public class Bean implements Serializable {

    private static Logger logger = Logger.getLogger(BEntityTree.class);
    private TreeNode entityTree;    
    private TreeNode selectedNode;

    public BEntityTree() {
        // irrelevant
    }

    @PostConstruct
    private void onPostConstruct() {
        logger.trace("start");

        //create tree
        TreeNode aux, aux2;
        this.entityTree = new DefaultTreeNode("root", null);
        aux = new DefaultTreeNode("type-0", "nodo 1", this.entityTree);
        aux2 = new DefaultTreeNode("type-1", "nodo 1.1", aux);      
    }

    // this.entityTree's getter-setter

    // this.selectedNode's getter-setter;

    public void onNodeSelect(NodeSelectEvent event) {       
        logger.trace("start");
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, 
"Selected", event.getTreeNode().toString());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public void onNodeExpand(NodeExpandEvent event) {
        //...
    }

    public void onNodeCollapse(NodeCollapseEvent event) {
        //...
    }
}

What am I doing wrong? Why onNodeSelect() listener is not even invoked when a node is selected?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
txapeldot
  • 71
  • 2
  • 10
  • The other events **are** fired? – Kukeltje Sep 12 '17 at 17:51
  • Not, any of them. – txapeldot Sep 12 '17 at 18:41
  • So your title is already to narrow... Sure you don't get any errors? Do you run your application in development mode? Did you read all in https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value ? – Kukeltje Sep 12 '17 at 18:44
  • So ajax with a plain `p:inputText` does work? Or is it just the tree that fails? Checked for duplicate primefaces versions? – Kukeltje Sep 13 '17 at 08:26

0 Answers0