简体   繁体   中英

RichFaces rich:tree nodeSelectListener not being listened to

I have a rich:tree component used like so:

                    <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:

    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. 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:

            <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. My backing bean method is also now:

    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 . I modified the faces-config.xml to include the 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. 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).

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. 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? 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.

Stumped.

I tried this facelets template and this sample java backing bean and the method was called. I assumed you use Seam but maybe I am wrong:) A little while ago there were some complaints: seam forum . What version of Richfaces are you using and what browser? If you use also Seam, please tell its version.

The fix for this was to install a facelets jar. See here . It affected other problems of mine, unsurprisingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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