未捕获的ReferenceError:$未在JSF Primefaces中定义

时间:2013-05-16 12:58:15

标签: jsf-2 primefaces

我正在使用Maven和Glassfish进行Primefaces项目。我跟随mkyong关注tutorial。我已经按照所有步骤操作,但是当我运行项目时,我在浏览器控制台中收到此错误。

Uncaught ReferenceError: $ is not defined
(anonymous function)

以下是生成的htmls的一部分:

<form id="j_idt6" name="j_idt6" method="post" action="/jsfTest/faces/hello.xhtml" enctype="application/x-www-form-urlencoded">
 <input type="hidden" name="j_idt6" value="j_idt6" />
 <div id="j_idt6:j_idt7" style="visibility:hidden"><textarea id="j_idt6:j_idt7_input"  name="j_idt6:j_idt7_input">This editor is provided by PrimeFaces dfsdf</textarea></div><script id="j_idt6:j_idt7_s" type="text/javascript">$(function() {PrimeFaces.cw('Editor','widget_j_idt6_j_idt7',{id:'j_idt6:j_idt7'},'editor');});</script> 
  <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="2416258137569200952:-2734382740508742283" autocomplete="off" />

并且没有显示主要编辑器。 但是服务器日志中没有错误。 这是我的文件:

hello.xhtml(欢迎文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
    >

<h:body>
<h:form>
    <p:editor value="#{editor.value}" />
</h:form>
</h:body>
</html>

我的web.xml

 <!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

 <web-app>
  <display-name>Archetype Created Web Application</display-name>

 <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
 </context-param>


<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>


<!-- Map these files with JSF -->
<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>*.jsf</url-pattern>
</servlet-mapping>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>faces/hello.xhtml</welcome-file>
</welcome-file-list>

</web-app>

my glassfish-web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server    
3.1 Servlet 3.0//EN"
   "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
  <parameter-encoding default-charset="UTF-8"/>
</glassfish-web-app>

我的托管bean:

import javax.faces.bean.ManagedBean;

@ManagedBean(name = "editor")
public class EditorBean {

private String value = "This editor is provided by PrimeFaces";

public String getValue() {
    return value;
}

 public void setValue(String value) {
    this.value = value;
 }
}

最后,我的pom.xml看起来像:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org        /2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-  v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.anixtech.jsf</groupId>
<artifactId>jsfTest</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jsfTest Maven Webapp</name>
<url>http://maven.apache.org</url>

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>Prime Repo</name>
        <url>http://repository.primefaces.org</url>
    </repository>
</repositories>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>3.3</version>
    </dependency>

    <!-- JSF 2 -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.11</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.11</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>

    <!-- EL -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
    </dependency>

</dependencies>
<build>
  <finalName>jsfTest</finalName>
   <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
          </configuration>
      </plugin>
  </plugins>
 </build>

我不知道我做错了什么。 任何的想法? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

这个问题没有答案,也没有标记为已回答,但BalusC解决方案对我和提出问题的人起了作用,所以我会听取并请将问题标记为已回答: 您应该在XHTML文件中添加<h:head>