PrimeFaces树选择为null



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

我试图将Tree上的选定节点设置为我的backingbean中的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;
    }
}

是否尝试通过日志记录验证selectedNode是否为null?也许它正在被设置,但<p:commandButton>update属性设置不正确。请记住,默认情况下,<h:form>会将其id前置到子元素。

同时验证<h:form> 中的其他元素是否没有引发验证错误

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

我在JSF模板客户端中有Tree组件,模板中有表单。将表单移动到客户端页面成功。我能够保持后备bean RequestScoped。

相关内容

  • 没有找到相关文章

最新更新