简体   繁体   English

RichFaces rich:tree nodeSelectListener未被收听

[英]RichFaces rich:tree nodeSelectListener not being listened to

I have a rich:tree component used like so: 我有一个rich:tree组件,其用法如下:

                    <rich:tree switchType="client" value="#{MyBacking.logTree}"
                    reRender="selectedLog" var="item" nodeFace="#{item.type}"
                    nodeSelectListener="#{MyBacking.processLogSelection}"
                    style="width: 50px;">
                    <rich:treeNode type="folder"
                        icon="/img/logListFolderIconClosed.png"
                        iconLeaf="/img/logListFolderIconOpen.png">
                        <h:outputText value="#{item.name}" />
                    </rich:treeNode>
                    <rich:treeNode type="log" iconLeaf="/img/logFileIcon.png"
                        icon="/img/logFileIcon.png">
                        <h:outputText value="#{item.name}" />
                    </rich:treeNode>
                </rich:tree>

and my MyBacking processLogSelection() method is: 我的MyBacking processLogSelection()方法是:

    public void processLogSelection(NodeSelectedEvent event) {
    logger.info("In processLogSelection");
    HtmlTree tree = (HtmlTree) event.getComponent();
    nodeTitle = (String) tree.getRowData();
    selectedNodeChildren.clear();
    TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
    if (currentNode.isLeaf()){
        selectedNodeChildren.add((String)currentNode.getData());
    } else {
        Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
        while (it != null && it.hasNext()) {
            Map.Entry<Object, TreeNode> entry = it.next();
            selectedNodeChildren.add(entry.getValue().getData().toString()); 
            logger.info("selected node: " + entry.getValue().getData().toString());
        }
    }
}

But when the page renders the tree (fine) clicking on a node highlights the node but nothing is logged from either of the bean logger calls - the method is just not being called. 但是,当页面呈现树(精细)时,在节点上单击会突出显示该节点,但是任何一个Bean logger调用都不会记录任何内容-该方法只是不被调用。 Any help answering why this might be would be greatly appreciated. 任何帮助回答为什么会这样的帮助将不胜感激。 Mark 标记

EDIT Added suggested tags/simplified bean method - still doesn't appear to get response from the bean as far as logs go: 编辑添加了建议的标签/简化的bean方法-就日志而言,似乎仍未从bean获得响应:

            <h:panelGrid columns="2" border="0" width="100%" rowClasses="tt">
            <rich:panel styleClass="panelLogTree" header="Log Select">
                <h:form>
                    <rich:tree switchType="client" value="#{MyBacking.logTree}"
                        var="item" nodeFace="#{item.type}" reRender="selectedLog"
                        nodeSelectListener="#{MyBacking.processLogSelection}"
                        ajaxSubmitSelection="true" style="width: 50px;">
                        <rich:treeNode type="folder"
                            icon="/img/logListFolderIconClosed.png"
                            iconLeaf="/img/logListFolderIconOpen.png">
                            <h:outputText value="#{item.name}" />
                        </rich:treeNode>
                        <rich:treeNode type="log" iconLeaf="/img/logFileIcon.png"
                            icon="/img/logFileIcon.png">
                            <h:outputText value="#{item.name}" />
                        </rich:treeNode>
                    </rich:tree>
                </h:form>
            </rich:panel>

            <rich:panel styleClass="panelLogOutput" header="Log Content">
                <h:outputText escape="false"
                    value="Log content: #{MyBacking.nodeTitle}" id="selectedLog" />
            </rich:panel>
        </h:panelGrid>
    </rich:tab>

Note the end rich:tab as this tree is rendering in a tab, from an included jsp file. 请注意rich:tab结尾,因为此树是从包含的jsp文件在选项卡中呈现的。 My backing bean method is also now: 我的后备bean方法现在也是:

    public void processLogSelection(NodeSelectedEvent event) {
    logger.info("In processLogSelection");
}

FURTHER EDIT Interestingly, I thought I'd rip back to a basic working model. 进一步编辑有趣的是,我认为我会回到一种基本的工作模型。 I took the code from the RichFaces Demo Page . 我从RichFaces演示页面中获取了代码。 I modified the faces-config.xml to include the SimpleTreeData bean. 我修改了faces-config.xml以包含SimpleTreeData bean。 I had trouble getting the bean code which reads the data file in ( simple-tree-data.properties ) so I used a FileReader instead. 我很难获得在( simple-tree-data.properties )中读取数据文件的bean代码,因此我改用FileReader This built ok, and I got a modified index.jsp jsf page to list the simple tree example as on the demo page, except clicking on a list item didn't report the selected nodeTitle to the specified place (same problem). 这样就好了,我得到了一个经过修改的index.jsp jsf页面,以在演示页面上列出简单的树示例,除了单击列表项未将选定的nodeTitle报告给指定的位置(同样的问题)。

I can see this either as the same problem reported above or the fact that the loadTree method in the SimpleTreeData.java bean has been changed. 我可以将其视为上面报告的相同问题,或者将SimpleTreeData.java bean中的loadTree方法更改为事实。 In the change, I removed the following lines and changed extraneous code as appropriate: 在更改中,我删除了以下几行,并适当地更改了无关的代码:

        FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);

As mentioned earlier, I used a FileReader but does anyone think this problem could be related to me removing these 3 lines? 如前所述,我使用了FileReader但有人认为这个问题可能与我删除这3行有关吗? As also listed above, my processLogSelection method doesn't use getCurrentInstance but I'm not sure it needs to if ajaxSubmitSelection="true" is listed in the JSF. 就像上面也列出的那样,我的processLogSelection方法不使用getCurrentInstance但是我不确定如果JSF中列出了ajaxSubmitSelection="true"它就不需要。

Stumped. 难过

I tried this facelets template and this sample java backing bean and the method was called. 我尝试了这个facelets模板和这个示例Java支持bean ,并调用了该方法。 I assumed you use Seam but maybe I am wrong:) A little while ago there were some complaints: seam forum . 我以为您使用的是Seam,但也许我错了:)不久前,有些投诉: seam forum What version of Richfaces are you using and what browser? 您正在使用什么版本的Richfaces和什么浏览器? If you use also Seam, please tell its version. 如果还使用Seam,请告知其版本。

The fix for this was to install a facelets jar. 解决此问题的方法是安装facelets jar。 See here . 这里 It affected other problems of mine, unsurprisingly. 毫不奇怪,它影响了我的其他问题。

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

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