简体   繁体   English

无法在嵌套TabView中展开TreeTable的节点

[英]Cannot expand node of treetable in nested tabviews

When I have a p:treeTable inside p:tabView inside p:tabView as a second tab, I'm unable to expand/collapse the nodes. 当我有一个p:treeTablep:tabView内部p:tabView作为第二个选项卡,我无法展开/折叠的节点。 But this happen only in this very specific scenario, which I've refined into minimal code: 但这仅在非常具体的情况下才会发生,我将其简化为最少的代码:

<h:form id="mainForm">
    <p:tabView id="outer" dynamic="false">
        <p:tab id="outer1">
        </p:tab>
        <p:tab id="outer2">
            <p:tabView id="inner" dynamic="false">
                <p:tab id="inner1">
                    <p:treeTable value="#{someBB.root}" var="wrapper">
                        <p:column>
                            #{wrapper}
                        </p:column>
                    </p:treeTable>
                </p:tab>
                <p:tab>
                    <p:tab id="inner2">
                        <p:treeTable value="#{someBB.root}" var="wrapper">
                            <p:column>
                                #{wrapper}
                            </p:column>
                        </p:treeTable>
                    </p:tab>
                </p:tab>
            </p:tabView>
        </p:tab>
    </p:tabView>
</h:form>

The model is also minimal: 该模型也是最小的:

private TreeNode root;
{
    root = new DefaultTreeNode("root", null);
    TreeNode documents = new DefaultTreeNode("root", root);
    new DefaultTreeNode("node1", documents);
    new DefaultTreeNode("node2", documents);
}

public TreeNode getRoot(){
    return root;
}

So when I open the page, go to outer2 tab, I'm not able to expand the node in the inner1's treeTable. 因此,当我打开页面时,转到external2选项卡,我无法在inner1的treeTable中展开该节点。 But when I switch to inner2, I can expand the nodes in that treeTable. 但是,当我切换到inner2时,我可以扩展该treeTable中的节点。 And what is more strange is that when I switch back to inner1, I can expand the nodes there as well now. 更奇怪的是,当我切换回inner1时,现在也可以在其中扩展节点。 It is also correct if there are no nested tabviews. 如果没有嵌套的tabview,那也是正确的。

Also when I remove the outer1 tab, the behavior is correct. 另外,当我删除outer1选项卡时,行为是正确的。

Also sharing the model doesn't affect this(I've tried having different model for each treeTable, but the behavior was the same). 另外,共享模型不会对此产生影响(我尝试为每个treeTable使用不同的模型,但是行为是相同的)。

Could there be some reason for this or is it a bug in PrimeFaces? 可能有某些原因吗?还是PrimeFaces中的错误?

I use Primefaces 4.0 我使用Primefaces 4.0

Some thoughts, but the answer to your question should be inside... 有些想法,但是您问题的答案应该在内部...

Well, first of all, your model has to be in a scope that allows it to keep its state between requests, otherwise you'll always have the absolute same tree (as in each request the tree model "root" will be generated again). 好吧,首先,您的模型必须在允许其在请求之间保持其状态的范围内,否则您将始终拥有绝对相同的树(因为在每个请求中,树模型“根”将再次生成) 。 Other important thing to notice is that you have to keep the root, your method should be something like this: 需要注意的另一重要事项是您必须保留根目录,您的方法应如下所示:

private TreeNode root;
{
    if (root != null)
        return root;

    root = new DefaultTreeNode("root", null);
    TreeNode documents = new DefaultTreeNode("root", root);
    new DefaultTreeNode("node1", documents);
    new DefaultTreeNode("node2", documents);
}

public TreeNode getRoot(){
    return root;
}

And you must remember to update the right tree (and I think keep just one tree updated is rather complex, imagine two!). 而且您必须记住要更新正确的树(而且我认为仅更新一棵树是相当复杂的,想象两棵!)。 And last, but not least, never use one model to both trees, you're messing everything, near impossible to makes things work properly in this situation. 最后但并非最不重要的一点是,永远不要对两棵树都使用一种模型,因为这会弄乱一切,在这种情况下几乎不可能使事情正常进行。 Try to use two models and keep the treemodel (root) with an apropriate scope (@ViewScoped or @SessionScoped in backing bean or @Session in a CDI bean). 尝试使用两个模型,并在树模型(根模型)中保留适当的范围(在后备bean中使用@ViewScoped或@SessionScoped或在CDI bean中使用@Session)。

I hope this can help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM