Richfaces tree is giving me an “Uncaught ReferenceError tree is not defined”

大憨熊 提交于 2019-12-25 12:53:09

问题


I believe my problem is in a settings file somewhere, but I have no idea what file/setting that would be. I have a standalone project with a working tree, but when I try to integrate it with my real project I start getting the mentioned error. That's what makes me think I have a setting somewhere that's off. I'm using JSF1.2 and richfaces 3.3.3. Here's my JSP file.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%-- jsf:pagecode language="java" location="/src/java/pagecode/agencyMappingPages/mapping/Mapping.java" --%><%-- /jsf:pagecode --%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>
<html>
    <f:view>
        <body>
            <rich:tree switchType="client" value="#{mappingBean.nodes}" var="node">
            </rich:tree>
        </body>
    </f:view>
</html>

Here's my bean code:

public TreeNode<String> getNodes() {
    TreeNodeImpl<String> nodes = new TreeNodeImpl<String>();
    TreeNodeImpl<String> root = new TreeNodeImpl<String>(); 
    root.setData("Test Tree Root");
    nodes.addChild(0, root);

    return nodes;
}

I'm using the following jars. These are also the three jars I'm using in the functioning version of my tree.

richfaces-api-3.3.3.Final.Jar
richfaces-impl-3.3.3.Final.Jar
richfaces-ui-3.3.3.Final.Jar

I've got the following in my web.xml file.

<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>
    <servlet-name>JavaScript Resource Servlet</servlet-name>
    <servlet-class>com.ibm.faces.webapp.JSResourceServlet</servlet-class>
    <load-on-startup>-1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Tiles2Servet</servlet-name>
    <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
    <init-param>
        <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
        <param-value>/WEB-INF/tiles20-defs.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>JavaScript Resource Servlet</servlet-name>
    <url-pattern>/.ibmjsfres/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

Not sure if this'll be helpful, but here's the javascript it chokes on. I had to omit quite a bit because the form wouldn't submit. I copied this from Chrome's developers window. It throws the exception at the second line: var tree = new tree......

<script type="text/javascript">(function() {
var tree = new Tree("j_id_jsp_1558828084_1", "j_id_jsp_1558828084_1:input", "client",
    {
    onselect: "", 
    onexpand: "", 
    oncollapse: "",
    oncontextmenu: "" 
},
function(event) {var params = {'j_id_jsp_1558828084_1:selectedNode':event.selectedNode} ;
if (!params.ajaxSingle && event.ajaxSingle) {
params.ajaxSingle = event.ajaxSingle;
}

So, what necessary file/setting am I missing? I'm sure I'm forgetting the most important piece of info which is why I need you. Thanks, Dale


回答1:


So I figured out what the problem was. For some reason Richfaces was not sending the script or styling files to the browser. It dynamically puts the links in the head. So I add the following filters to the web.xml file and everything is happy now including me and my partner.

<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>ALL</param-value>
</context-param> 
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>

Hopefully this helps someone else.



来源:https://stackoverflow.com/questions/8174816/richfaces-tree-is-giving-me-an-uncaught-referenceerror-tree-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!