如何在jsf中使用节点文本或节点值获取DefaultMutableTreeNode

发布于 2024-10-28 03:26:34 字数 126 浏览 0 评论 0原文

我的icefaces树有问题,我没有获得支持bean中的当前节点值。所以,我决定使用nodevalue(文本)来获取值。谁能告诉我,如何使用节点值(字符串)获取 DefaultMutableTreeNode,以便我可以将其设置为当前节点。

I am having problem with my icefaces tree, I am not getting the current node value in backing bean. So, I decided to get the value using nodevalue (text). Can anyone tell me, how can I get the DefaultMutableTreeNode using nodevalue (string) so I can set it as currentnode.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2024-11-04 03:26:34

我实际上是在猜测你的问题。我不太清楚你的意思,但我会尝试一下。它可能对你有帮助。

这是我的一个旧项目。我还建议现在使用 Primefaces。更容易使用,更容易主题化,更快(根据我的经验),并且组件更多。

 <ice:tree id="tree"
                          value="#{TreeController.model}"
                          var="node"
                          hideRootNode="false"
                          hideNavigation="false"
                          imageDir="./xmlhttp/css/rime/css-images/">
                    <ice:treeNode>
                        <f:facet name="icon">
                            <ice:panelGroup style="display: inline">
                                <h:graphicImage value="#{node.userObject.icon}"/>
                            </ice:panelGroup>
                        </f:facet>
                        <f:facet name="content">
                            <ice:panelGroup  style="display: inline">
                                <ice:commandLink disabled="#{!PkgLineTableController.tableRendered}"
                                                 actionListener="#{TreeController.locationNodeSelected}">
                                    <f:param name="treeId"
                                             value="#{node.userObject.tree.treeId}"/>
                                    <f:param name="name" value="#{node.userObject.text}"/>
                                    <ice:outputText  id="TreeNode"
                                                     value="#{node.userObject.text}"/>
                                </ice:commandLink>
                            </ice:panelGroup>
                        </f:facet>
                    </ice:treeNode>
                </ice:tree>

支撑豆:

 private DefaultMutableTreeNode findTreeNode(String nodeId) {

        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) getModel().getRoot();
        DefaultMutableTreeNode node;
        TreeObject tmp;
        Enumeration nodes = rootNode.depthFirstEnumeration();
        while (nodes.hasMoreElements()) {
            node = (DefaultMutableTreeNode) nodes.nextElement();
            tmp = (TreeObject) node.getUserObject();
            if (nodeId.equals(String.valueOf(tmp.getTree().getTreeId()))) {
                return node;
            }
        }
        return null;
    }

    /**
     *  Method fired when a node is selected on the tree.  This calls a few methods from the packageLineBean to build the
     *  package line list.
     */
    public void locationNodeSelected(ActionEvent event) {

        PkgLineTableController pkgLineTableController = PkgLineTableController.getCurrentInstance();

        String tree_id = FacesUtils.getRequestParameter("treeId");
        selectedTreeNodeName = FacesUtils.getRequestParameter("name");
        DefaultMutableTreeNode node = findTreeNode(tree_id);
        selectedTreeObject = ((TreeObject) node.getUserObject());

        pkgLineTableController.getPkgLineTreeList().clear();
        pkgLineTableController.digPackageLines(Integer.parseInt(tree_id));
        pkgLineTableController.setEffect(new Appear());

        WrapSpecTableController.getCurrentInstance().getWrapSpecList().clear();
    }

I'm actually guessing on your question. I'm not exactly sure what you mean but I'm going to take a shot. It may help you.

This is from an old project of mine. I would also suggest using Primefaces now. Much easier to work with, easier to theme, faster(from my experience), and more components.

 <ice:tree id="tree"
                          value="#{TreeController.model}"
                          var="node"
                          hideRootNode="false"
                          hideNavigation="false"
                          imageDir="./xmlhttp/css/rime/css-images/">
                    <ice:treeNode>
                        <f:facet name="icon">
                            <ice:panelGroup style="display: inline">
                                <h:graphicImage value="#{node.userObject.icon}"/>
                            </ice:panelGroup>
                        </f:facet>
                        <f:facet name="content">
                            <ice:panelGroup  style="display: inline">
                                <ice:commandLink disabled="#{!PkgLineTableController.tableRendered}"
                                                 actionListener="#{TreeController.locationNodeSelected}">
                                    <f:param name="treeId"
                                             value="#{node.userObject.tree.treeId}"/>
                                    <f:param name="name" value="#{node.userObject.text}"/>
                                    <ice:outputText  id="TreeNode"
                                                     value="#{node.userObject.text}"/>
                                </ice:commandLink>
                            </ice:panelGroup>
                        </f:facet>
                    </ice:treeNode>
                </ice:tree>

Backing bean:

 private DefaultMutableTreeNode findTreeNode(String nodeId) {

        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) getModel().getRoot();
        DefaultMutableTreeNode node;
        TreeObject tmp;
        Enumeration nodes = rootNode.depthFirstEnumeration();
        while (nodes.hasMoreElements()) {
            node = (DefaultMutableTreeNode) nodes.nextElement();
            tmp = (TreeObject) node.getUserObject();
            if (nodeId.equals(String.valueOf(tmp.getTree().getTreeId()))) {
                return node;
            }
        }
        return null;
    }

    /**
     *  Method fired when a node is selected on the tree.  This calls a few methods from the packageLineBean to build the
     *  package line list.
     */
    public void locationNodeSelected(ActionEvent event) {

        PkgLineTableController pkgLineTableController = PkgLineTableController.getCurrentInstance();

        String tree_id = FacesUtils.getRequestParameter("treeId");
        selectedTreeNodeName = FacesUtils.getRequestParameter("name");
        DefaultMutableTreeNode node = findTreeNode(tree_id);
        selectedTreeObject = ((TreeObject) node.getUserObject());

        pkgLineTableController.getPkgLineTreeList().clear();
        pkgLineTableController.digPackageLines(Integer.parseInt(tree_id));
        pkgLineTableController.setEffect(new Appear());

        WrapSpecTableController.getCurrentInstance().getWrapSpecList().clear();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文