【发布时间】:2011-01-20 15:33:26
【问题描述】:
我有一个像这样使用的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>
而我的 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());
}
}
}
但是当页面呈现树(很好)时,单击一个节点会突出显示该节点,但任何一个 bean 记录器调用都没有记录任何内容 - 该方法只是没有被调用。任何回答为什么会这样的帮助将不胜感激。 标记
编辑添加了建议的标签/简化的 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>
注意rich:tab 的结尾,因为这棵树正在一个选项卡中呈现,来自一个包含的 jsp 文件。我的backing bean方法现在也是:
public void processLogSelection(NodeSelectedEvent event) {
logger.info("In processLogSelection");
}
进一步编辑
有趣的是,我想我会回到一个基本的工作模型。我从RichFaces Demo Page 获取了代码。我修改了 faces-config.xml 以包含 SimpleTreeData bean。我在获取读取 (simple-tree-data.properties) 中的数据文件的 bean 代码时遇到了麻烦,所以我改用了 FileReader。这构建好了,我得到了一个修改过的 index.jsp jsf 页面来列出演示页面上的简单树示例,除了单击列表项没有将选定的nodeTitle 报告到指定的位置(同样的问题)。
我可以将其视为与上面报告的相同问题或SimpleTreeData.java bean 中的loadTree 方法已更改的事实。在更改中,我删除了以下几行并酌情更改了无关代码:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);
如前所述,我使用了FileReader,但有人认为这个问题可能与我删除这 3 行有关吗?如上所述,我的 processLogSelection 方法不使用 getCurrentInstance 但我不确定是否需要在 JSF 中列出 ajaxSubmitSelection="true"。
难倒。
【问题讨论】:
-
您是否尝试过将 ajaxSubmitSelection="true" 作为rich:tree 的属性?啊,确保 rich:tree 被一个表单包围。
-
谢谢。我都试过了,都没有成功。我会多做一些实验,然后回来报告。
-
ajaxSubmitSelection="true"应该可以工作(在这里可以工作)- 检查您的日志以了解为什么不工作。 -
rich:tree是a4j:included 页面的一部分是否重要? -
我尝试将上面的代码嵌套在 tabpanel 中,它仍然有效。开个玩笑,但你确定你的日志记录有效吗:)