我用primefaces树组件写了一些页面。我想在树节点选择后更新outputLabel。标签应显示当前所选节点的名称。我的问题在于primefaces在托管bean中启动此事件的监听器。听众方法根本没有被调用。我能够更新outputLabel(使用其他bean的当前时间值),但我不能使用listener方法。这是我的页面片段():
<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}" />
这是托管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();
}
}
目前,我正在使用NetBeans 8软件包在Glassfish v4上运行此代码。首先我使用PrimeFaces 4.0,但现在它在PrimeFaces 5.1上运行。没效果。
更新:整页代码:http://pastebin.com/vEPtWtw2
答案 0 :(得分:1)
您应该在p:tree
中嵌套h:form
,因为JSF表单使用“post-back”技术将表单数据提交回包含表单的页面。