Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PrimeFaces树选择为空_Java_Jsf_Jsf 2_Primefaces - Fatal编程技术网

Java PrimeFaces树选择为空

Java PrimeFaces树选择为空,java,jsf,jsf-2,primefaces,Java,Jsf,Jsf 2,Primefaces,我在Glassfish 3.1上使用PrimeFaces 2.2.1树组件 我试图将树上的选定节点设置为我的支持bean中的TreeNode对象,但它始终为null 我在PrimeFaces论坛上请求支持,但不幸的是没有得到回复 <p:tree id="contextTree" value="#{contextTreeBean.contextRoot}" var="node" selectionMode="single" selection="#{contextTreeBean.selec

我在Glassfish 3.1上使用PrimeFaces 2.2.1树组件

我试图将树上的选定节点设置为我的支持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;
    }
}

@ManagedBean
@请求范围
公共类contextTreeBean{
@EJB
私人contextFacade本地contextFacade;
私有上下文=新上下文();
私有树节点上下文根;
私有树节点选择节点;
私有字符串输出;
/**创建contextTreeBean的新实例*/
公共上下文Treebean(){
}
public void createContext(){
输出=selectedNode.getData().toString();
}
公共字符串getOutput(){
返回输出;
}
公共void setOutput(字符串输出){
这个。输出=输出;
}
公共树节点getSelectedNode(){
返回selectedNode;
}
公共无效集合selectedNode(TreeNode selectedNode){
this.selectedNode=selectedNode;
}
公共上下文getContext(){
返回上下文;
}
公共void setContext(上下文){
this.context=上下文;
}
公共ContextFacadeLocal getContextFacade(){
返回contextFacade;
}
公共void setContextFacade(ContextFacadeLocal contextFacade){
this.contextFacade=contextFacade;
}
公共树节点getContextRoot(){
返回contextRoot;
}
公共void setContextRoot(TreeNode contextRoot){
this.contextRoot=contextRoot;
}
@施工后
构造后的私有void(){
populateContextTree();
}
私有void populateContextTree(){
buildContextTree(新的DefaultTreeNode(“Root”,null),contextFacade.findRootContexts());
}
私有void buildContextTree(TreeNode父节点,列出子节点){
对于(上下文currentContextNode:子级){
TreeNode tempNode=新的DefaultTreeNode(currentContextNode,parentNode);
buildContextTree(tempNode,currentContextNode.getChildren());
}
contextRoot=parentNode;
}
}

您是否尝试通过日志记录验证
selectedNode
是否为空?可能正在设置,但您的
更新属性设置不正确。请记住,默认情况下,
会将其id前置到子元素

还要验证


此外,我仍然不相信Primefaces树组件在得到
@RequestScoped
托管bean支持时能够正常工作。尝试将托管bean更改为
@ViewScoped
,这样托管bean的生命周期将跨越各个请求。

我在JSF模板客户机中使用了树组件,模板中有表单。将表单移动到客户机页面是有效的。我能够保持支持bean requestscope的状态。

如果您将bean更改为查看范围或会话范围,它会工作吗?我在JSF模板客户机中使用了树组件,模板中有表单。将表单移动到客户机页面是有效的。我能够保持支持bean请求的范围。模板客户端中是否应该始终包含表单组件?@Laurence,是的,您会发现通常每个客户端页面都应该至少包含一个表单。此外,您可能会遇到一些Primefaces错误,您需要多个表单。例如,如果您在一个页面上有多个对话框组件,最好将每个对话框的内容放在一个单独的表单中。因此,您基本上是嵌套表单?我在模板中有一个表单,但没有模板客户端。我以为表单会暴露在客户端页面上,但显然不会。