我在Glassfish 3.1上使用PrimeFaces 2.2.1 Tree组件
我正在尝试将树上的选定节点设置为我的支持bean中的TreeNode对象,但它始终为null。
我在PrimeFaces论坛上寻求支持,但遗憾的是没有得到回复。
<p:tree id="contextTree" value="#{contextTreeBean.contextRoot}" var="node" selectionMode="single" selection="#{contextTreeBean.selectedNode}">
<p:treeNode>
<h:outputText value="#{node.name}"/>
</p:treeNode>
</p:tree>
<h:outputText id="output" value="#{contextTreeBean.output}"/>
<p:commandButton id ="createButton" value="+" actionListener="#{contextTreeBean.createContext()}" update="contextTree, output"/>
@ManagedBean
@RequestScoped
public class contextTreeBean {
@EJB
private ContextFacadeLocal contextFacade;
private Context context = new Context();
private TreeNode contextRoot;
private TreeNode selectedNode;
private String output;
/** Creates a new instance of contextTreeBean */
public contextTreeBean() {
}
public void createContext() {
output = selectedNode.getData().toString();
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
public ContextFacadeLocal getContextFacade() {
return contextFacade;
}
public void setContextFacade(ContextFacadeLocal contextFacade) {
this.contextFacade = contextFacade;
}
public TreeNode getContextRoot() {
return contextRoot;
}
public void setContextRoot(TreeNode contextRoot) {
this.contextRoot = contextRoot;
}
@PostConstruct
private void postConstruct() {
populateContextTree();
}
private void populateContextTree() {
buildContextTree(new DefaultTreeNode("Root", null), contextFacade.findRootContexts());
}
private void buildContextTree(TreeNode parentNode, List<Context> children) {
for (Context currentContextNode : children) {
TreeNode tempNode = new DefaultTreeNode(currentContextNode, parentNode);
buildContextTree(tempNode, currentContextNode.getChildren());
}
contextRoot = parentNode;
}
}
答案 0 :(得分:2)
您是否尝试通过记录验证selectedNode
是否为空?可能已设置,但update
的{{1}}属性未正确设置。请记住,默认情况下,<p:commandButton>
会将其ID添加到子元素中。
同时验证<h:form>
此外,我还不相信Primefaces树组件在由<h:form>
托管bean支持时可以正常工作。尝试将托管bean更改为@RequestScoped
,以便托管bean的生命周期跨越各个请求。
答案 1 :(得分:0)
我在一个JSF模板客户端中有Tree组件,模板中有表单。将表单移动到客户端页面工作。我能够保持支持bean RequestScoped。