<rich:tree>示例reRender不工作Richfaces 3.3.4 final </rich:tree>

时间:2015-01-20 09:06:08

标签: jsf tree richfaces rerender

我在SAP NetWeaver AS 7.31上使用Richfaces 3.3.4 final和JSF 1.2。

现在我面临一些问题,从h:outputText中的rich:tree动态显示所选节点。 selectedNodeListener被正确调用,Node的名称保存在String中,但是我的h:outputText只刷新页面刷新而不是选择,就像Showcases(http://showcase-rf3.richfaces.org/richfaces/tree.jsf?tab=model&cid=26981)中的例子一样。

有人知道这是上述安装程序的常见问题还是我错过了什么?据我所知,SAP NetWeaver不在支持的服务器列表中,但符合JEE5标准。这可能是原因吗?

我简化了Richfaces Showcases中的Example,以在小型环境中重现问题。这是一些代码:

SimpleTreeBean.java

import java.util.ArrayList;  
import java.util.Iterator;  
import java.util.List;  
import java.util.Map;  

import org.richfaces.component.html.HtmlTree;  
import org.richfaces.event.NodeSelectedEvent;  
import org.richfaces.model.TreeNode;  
import org.richfaces.model.TreeNodeImpl;  

public class SimpleTreeBean {  
    private TreeNode rootNode = null;  
    private List<String> selectedNodeChildren = new ArrayList<String>();  

    private String nodeTitle;  


    private void loadTree() {  
            rootNode = new TreeNodeImpl();  
            TreeNodeImpl rt = new TreeNodeImpl();  
            rt.setData("Root");  
            rootNode.addChild(1, rt);  
            for(int i = 1; i <= 5; i++){  
                TreeNodeImpl child = new TreeNodeImpl();  
                child.setData("Child "+i);  
                rt.addChild(i, child);  
            }  
    }  

    public void processSelection(NodeSelectedEvent event) {  
        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());  
            }  
        }  
    }  

    public TreeNode getTreeNode() {  
        if (rootNode == null) {  
            loadTree();  
        }  

        return rootNode;  
    }  

    public String getNodeTitle() {  
        return nodeTitle;  
    }  

    public void setNodeTitle(String nodeTitle) {  
        this.nodeTitle = nodeTitle;  
    }  
}  

test.jsp的:

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>  
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>  
<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>  
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>  

<html>  
<head>  
<title>TestTree</title>  
</head>  
<body>  
<f:view>  
 <h:form>      
        <h:panelGrid columns="2" width="100%" columnClasses="col1,col2">  

            <rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}"   
                reRender="selectedNode" ajaxSubmitSelection="true"  switchType="client"  
                value="#{simpleTreeBean.treeNode}" var="item" ajaxKeys="#{null}">  
            </rich:tree>  

            <h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />  

        </h:panelGrid>  
    </h:form>  
</f:view>  
</body>  
</html>  

faces-config.xml的重要部分:

<?xml version="1.0" encoding="UTF-8"?>  

<faces-config  
    xmlns="http://java.sun.com/xml/ns/javaee"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"  
    version="1.2">  
    <managed-bean>  
        <managed-bean-name>simpleTreeBean</managed-bean-name>  
        <managed-bean-class>  
            com.realcore.web.beans.SimpleTreeBean  
        </managed-bean-class>  
        <managed-bean-scope>session</managed-bean-scope>  
    </managed-bean>  

</faces-config>  
<</faces-config>/faces-config>  

此外,我的faces-config中也有一些验证器和转换器。但我认为这对这个问题并不重要。

这是web.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    id="WebApp_ID" version="2.5">  
    <display-name>SstSapWEB</display-name>  
    <welcome-file-list>  
        <welcome-file>index.html</welcome-file>  
        <welcome-file>index.htm</welcome-file>  
        <welcome-file>index.jsp</welcome-file>  
        <welcome-file>login.jsp</welcome-file>  
        <welcome-file>default.html</welcome-file>  
        <welcome-file>default.htm</welcome-file>  
        <welcome-file>default.jsp</welcome-file>  
    </welcome-file-list>  

    <!-- Making the RichFaces skin spread to standard HTML controls -->  
    <context-param>  
        <param-name>org.richfaces.CONTROL_SKINNING</param-name>  
        <param-value>enable</param-value>  
    </context-param>  
    <!-- Defining and mapping the RichFaces filter -->  
    <filter>  
        <display-name>RichFaces Filter</display-name>  
        <filter-name>richfaces</filter-name>  
        <filter-class>org.ajax4jsf.Filter</filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>richfaces</filter-name>  
        <servlet-name>Faces Servlet</servlet-name>  
        <dispatcher>REQUEST</dispatcher>  
        <dispatcher>FORWARD</dispatcher>  
        <dispatcher>INCLUDE</dispatcher>  
    </filter-mapping>  

    <servlet>  
        <servlet-name>Faces Servlet</servlet-name>  
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>  
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
        <servlet-name>Faces Servlet</servlet-name>  
        <url-pattern>/faces/*</url-pattern>  
    </servlet-mapping>  
</web-app>  

这个简单的例子也不起作用。

我不知道如何修复或解决此问题。非常感谢任何帮助。

此致

丹尼尔

1 个答案:

答案 0 :(得分:0)

事实上其他人也有类似的问题:在同时处理其他事情后,我现在想出了如何解决这个问题。

这很简单,所有工作都在JSP中完成:

  1. 在Rich Tree标记内使用Rich Tree节点
  2. 使用TreeNode的ajaxSubmitSelection和reRender属性
  3. 包裹页面的一部分,应该在<a4j:outputPanel/>中重新呈现并将其属性ajaxRendered设置为“true”
  4. 确保<a4j:outputPanel/>的id-Attribute和TreeNode的reRender属性的值相同。
  5. 希望这有助于其他有类似问题的人,

    丹尼尔