1
votes

I'm write some page with primefaces tree component. I want to update outputLabel after tree node selection. Label should display name of current selected node. My problem lies where primefaces launch listener for this event in managed bean. Listener method doesn't invoked at all. I'm able to update outputLabel (with current time value from other bean), but I can't use listener method. Here is my page fragment ():

<p:tree value="#{directoryTreeBuilder.root}"
        var="node"
        dynamic="true"
        style="border: none;"
        selectionMode="single"
        selection="#{directoryTreeBuilder.selected}">
    <p:ajax event="select"
            listener="#{directoryTreeBuilder.onDirSelected}"
            update=":currentDir"/>
    <p:treeNode>
        <h:outputText value="#{node}" />
    </p:treeNode>
</p:tree>
...
<h:outputText id="currentDir" value="#{directoryTreeBuilder.selected}" />

Here is managed bean:

@Named(value = "directoryTreeBuilder")
@SessionScoped
public class DirectoryTreeBuilder implements Serializable {

/**
 * Directory facade bean.
 */
@EJB
private DirectoryFacadeLocal dirBean;

/**
 * Tree structure root directory.
 */
private TreeNode root;

/**
 * Current selected directory.
 */
private DefaultTreeNode selected;

/**
 * Bean initialization method.
 */
@PostConstruct
public void init() {
    //Root initiation.
}

/**
 * Root getter.
 * @return root directory with structure;
 */
public TreeNode getRoot() {
    return root;
}

/**
 * Get selected directory node.
 * @return primefaces treenode;
 */
public TreeNode getSelected() {
    return selected;
}

public void setSelected(TreeNode selected) {
    this.selected = (DefaultTreeNode) selected;
}

/**
 * Selected event listener method.
 * @param e selection from primefaces
 */
public void onDirSelected(NodeSelectEvent e) {
    System.err.println("DIR SELECTED!");
    this.selected = (DefaultTreeNode) e.getTreeNode();
}
}

Currently I'm running this code on Glassfish v4 from NetBeans 8 package. Firstly I use PrimeFaces 4.0, but now it's running on PrimeFaces 5.1. No effect.

UPDATE: full page code: http://pastebin.com/vEPtWtw2

1
I think you problem derive from xhtml code that you did not show.wittakarn
Full page code added with pastebin (in OP).spoilt.exile

1 Answers

1
votes

You should nest p:tree inside h:form because JSF forms use the "post-back" technique to submit form data back to the page that contains the form.