有人是否已经出现此错误:
TypeError:jQuery.atmosphere是undefined packed.js:2261?
我没有找到任何关于此的文档,也没有找到问题的方法。(我添加了所有必需的依赖项)
这是我的test.xhtml:
<ui:composition template="/pages/template/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:b="http://richfaces.org/sandbox/bootstrap"
lang="fr">
<ui:define name="body">
<h:head>
<h:outputScript name="javax.faces:jsf.js" />
<h:outputScript name="jquery.js" />
</h:head>
<h:form>
<h:panelGrid columns="4">
<h:outputLabel value="Message:" />
<h:inputText id="messageInput" styleClass="message" value="# {richBean.message}">
</h:inputText>
<a4j:commandButton value="Send" action="#{richBean.sendMessage()}"
execute="@form" render="messageInput" />
<rich:messages for="messageInput" />
</h:panelGrid>
</h:form>
<h:form>
<h:panelGrid columns="3">
<a4j:push address="pushCdi"
ondataavailable="jQuery('<li />').prependTo('#messages').text(event.rf.data)" />
<ul id="messages" />
</h:panelGrid>
</h:form>
</ui:define>
我的RichBean.java:
import javax.annotation.PostConstruct;
import javax.enterprise.event.Event;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;
import org.richfaces.application.push.TopicKey;
import org.richfaces.application.push.TopicsContext;
import org.richfaces.cdi.push.Push;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import com.ocpsoft.pretty.faces.annotation.URLMappings;
import javax.inject.Named;
import org.richfaces.application.push.TopicKey;
import org.richfaces.application.push.TopicsContext;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@ManagedBean(name = "richBean")
@Scope(value = "session")
@URLMappings(mappings = { @URLMapping(id = "rich", pattern = "/test", viewId = "/test.xhtml") })
@Named
public class RichBean {
public static final String PUSH_CDI_TOPIC = "pushCdi";
private String message;
@Push(topic = PUSH_CDI_TOPIC)
@Inject
Event<String> pushEvent;
public void sendMessage() {
pushEvent.fire(message);
message = "";
}
}
和Template.xhtml:
<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core" lang="fr">
<ui:remove>
</ui:remove>
<html>
<c:set var="ctx" value="#{facesContext.externalContext.requestContextPath}" scope="request"/>
<c:set var="myContext" value="#{request.serverName}:#{request.serverPort}#{request.contextPath}" scope="request" />
<h:head>
<title>#{messages['title']}<ui:insert name="title"></ui:insert></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8;IE=7,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Cache-Control" content="private" />
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Cache-Control" content="max-stale=0" />
<link rel="shortcut icon" href="${ctx}/favicon.ico" />
<link rel="icon" type="image/ico" href="${ctx}/favicon.ico" />
<!-- CSS -->
<h:outputStylesheet library="css" name="style.css" />
<link href="${ctx}/resources/css/jquery-ui.css" rel="stylesheet"
type="text/css" media="screen" />
<link href="${ctx}/resources/css/bootstrap.min.css" rel="stylesheet"
type="text/css" media="screen" />
<link href="${ctx}/resources/css/bootstrap-theme.min.css" rel="stylesheet"
type="text/css" media="screen" />
<link href="${ctx}/resources/css/theme.css" rel="stylesheet"
type="text/css" media="screen" />
<link href="${ctx}/resources/css/footer.css" rel="stylesheet"
type="text/css" media="screen" />
<link href="${ctx}/resources/css/bootstrap-datetimepicker.min.css" rel="stylesheet"
type="text/css" media="screen" />
<!-- CSS end -->
<ui:insert name="headAdd" />
<ui:remove>
<!-- Enable usage of html5 with old browsers -->
</ui:remove>
<h:outputText value="<!--[if lt IE 9]>" escape="false" />
<h:outputScript library="js" name="html5.js" />
<h:outputText value="<![endif]-->" escape="false" />
<ui:remove>
</ui:remove>
<h:outputText value="<!--[if lte IE 7]>" escape="false" />
<link rel="stylesheet" type="text/css" href="#{resource['css:styleIE.css']}" />
<h:outputText value="<![endif]-->" escape="false" />
</h:head>
<h:body>
<div id="container" class="wrapper">
<header>
<ui:insert name="header">
<ui:include src="parts/header.xhtml" />
</ui:insert>
</header>
<ui:insert name="body">
<ui:include src="parts/body.xhtml" />
</ui:insert>
<div class="push"></div>
</div>
<div style="padding: 0px 15px 0px 15px;">
<div class="footer">
<ui:insert name="footer">
<ui:include src="parts/footer.xhtml" />
</ui:insert>
</div>
</div>
<h:outputScript library="jquery" name="jquery.js" target="head" />
<h:outputScript library="jquery" name="jquery-ui.js" target="head" />
<h:outputScript library="js" name="bootstrap.min.js" />
<h:outputScript library="js" name="moment.min.js" />
<h:outputScript library="js" name="bootstrap-datetimepicker.min.js" />
<h:outputScript library="js" name="table.js" />
<rich:jQuery selector=".stable tr:odd" query="addClass('odd-row')" />
<rich:jQuery selector=".stable tr:even" query="addClass('even-row')" />
<rich:jQuery selector=".stable tr" event="mouseover"
query="jQuery(this).addClass('active-row')" />
<rich:jQuery selector=".stable tr" event="mouseout"
query="jQuery(this).removeClass('active-row')" />
<rich:jQuery selector=".stable tr" event="click"
query="jQuery('.click-row').removeClass('click-row');jQuery(this).addClass('click-row')" />
<rich:notifyMessages showDetail="true" globalOnly="true" styleClass="my-alert alert-info" style="margin-top:15px;" stayTime="5000" nonblocking="true" />
</h:body>
</html>
</f:view>
我的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>
<artifactId>barApp</artifactId>
<packaging>war</packaging>
<name>barApp</name>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<richfaces.version>4.3.5.Final</richfaces.version>
<hibernate.version>3.6.0.Final</hibernate.version>
<cxf.version>2.6.1</cxf.version>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.6.1</version>
</plugin>
</plugins>
</reporting>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>${richfaces.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<version>0.0.1-Snapshot</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
<filters>
<filter>src/main/filters/application-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/jks</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>src/main/webapp/</warSourceDirectory>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Environment>${env}</Implementation-Environment>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<finalName>barApp</finalName>
</build>
<profiles>
<profile>
<id>tc6</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>jboss6</id>
<properties>
<env>dev</env>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>javax.xml.stream</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<!-- XML -->
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>xml-resolver</artifactId>
<groupId>xml-resolver</groupId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- HIBERNATE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<artifactId>cglib</artifactId>
<groupId>cglib</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
<exclusions>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>javax.xml.stream</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.0-b09</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.0-b09</version>
</dependency>
<!-- RICHFACES -->
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-jquery</artifactId>
<version>1.0.2</version>
<type>war</type>
</dependency>
</dependencies>
</project>
HTML生成:
<!DOCTYPE html>
<html><head>
<title>ITcketing</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8;IE=7,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Cache-Control" content="private" />
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Cache-Control" content="max-stale=0" />
<link href="/barApp/resources/css/jquery-ui.css" rel="stylesheet" type="text/css" media="screen" />
<link href="/barApp/resources/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen" />
<link href="/barApp/resources/css/footer.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="/barApp/javax.faces.resource/styleIE.css.xhtml?ln=css" /><![endif]--><link type="text/css" rel="stylesheet" href="/barApp/javax.faces.resource/style.css.xhtml?ln=css" /><script type="text/javascript" src="/barApp/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script><script type="text/javascript" src="/barApp/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.5.Final/PackedCompressed/jquery.js"></script><script type="text/javascript" src="/barApp/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.5.Final/PackedCompressed/packed/packed.js"></script><link type="text/css" rel="stylesheet" href="/barApp/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.5.Final/PackedCompressed/plain/packed/packed.css" /><script type="text/javascript" src="/barApp/javax.faces.resource/jquery.js.xhtml?ln=jquery"></script><script type="text/javascript" src="/barApp/javax.faces.resource/jquery-ui.js.xhtml?ln=jquery"></script></head><body>
<div id="container" class="wrapper">
<header>
<table class="hidden-sm hidden-xs" width="100%" style="margin-top:-20px;">
<tr>
<td width="33%"><img src="/barApp/resources/css/images/logo.png" height="100px" />
</td>
<td valign="middle">
<h1 style="color: #003561;">ITcketing</h1>
</td>
</tr>
</table>
</header><head><script type="text/javascript" src="RES_NOT_FOUND"></script></head>
<form id="j_idt25" name="j_idt25" method="post" action="/barApp/test" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt25" value="j_idt25" />
<table>
<tbody>
<tr>
<td><label>
Message:</label></td>
<td><input id="j_idt25:messageInput" type="text" name="j_idt25:messageInput" value="32" class="message" /></td>
<td><input id="j_idt25:j_idt28" name="j_idt25:j_idt28" onclick="RichFaces.ajax("j_idt25:j_idt28",event,{"incId":"1"} );return false;" value="Send" type="submit" /></td>
<td><span class="rf-msgs " id="j_idt25:j_idt29"></span></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-2268432026713773464:4752734078205348919" autocomplete="off" />
</form>
<form id="j_idt30" name="j_idt30" method="post" action="/barApp/test" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt30" value="j_idt30" />
<span id="j_idt30:pushJms"><script type="text/javascript">RichFaces.Push.setPushResourceUrl("/barApp/rfRes/org.richfaces.resource.PushResource.xhtml");new RichFaces.ui.Push("j_idt30:pushJms",{"address":"pushTopicsContext","ondataavailable":function(event){RichFaces.ajax(this,event,{"parameters":{"javax.faces.behavior.event":"dataavailable","org.richfaces.ajax.component":"j_idt30:pushJms"} ,"sourceId":this} )}} );</script></span><table>
<tbody>
<tr>
<td><label>
New UUID:</label></td>
<td><div id="j_idt30:uuid">
</div></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-2268432026713773464:4752734078205348919" autocomplete="off" />
</form>
<div class="push"></div>
</div>
<div style="padding: 0px 15px 0px 15px;">
<div class="footer">
<footer class="bs-docs-footer" role="contentinfo">
<div class="container"><img src="/barApp/resources/css/images/logo.png" height="80px" />
</div>
</footer>
</div>
</div><script type="text/javascript" src="/barApp/javax.faces.resource/bootstrap.min.js.xhtml?ln=js"></script><script type="text/javascript" src="/barApp/javax.faces.resource/moment.min.js.xhtml?ln=js"></script><script type="text/javascript" src="/barApp/javax.faces.resource/bootstrap-datetimepicker.min.js.xhtml?ln=js"></script><script type="text/javascript" src="/barApp/javax.faces.resource/table.js.xhtml?ln=js"></script><script type="text/javascript" src="RES_NOT_FOUND"></script><span id="j_idt46" style="display: none;"><script type="text/javascript">RichFaces.jQuery.query({"selector":".stable tr:odd","query":"addClass('odd\u002Drow')"} );</script></span><span id="j_idt47" style="display: none;"><script type="text/javascript">RichFaces.jQuery.query({"selector":".stable tr:even","query":"addClass('even\u002Drow')"} );</script></span><span id="j_idt48" style="display: none;"><script type="text/javascript">RichFaces.jQuery.query({"selector":".stable tr","event":"mouseover","query":"jQuery(this).addClass('active\u002Drow')"} );</script></span><span id="j_idt49" style="display: none;"><script type="text/javascript">RichFaces.jQuery.query({"selector":".stable tr","event":"mouseout","query":"jQuery(this).removeClass('active\u002Drow')"} );</script></span><span id="j_idt50" style="display: none;"><script type="text/javascript">RichFaces.jQuery.query({"selector":".stable tr","event":"click","query":"jQuery('.click\u002Drow').removeClass('click\u002Drow');jQuery(this).addClass('click\u002Drow')"} );</script></span><span class="rf-ntf-msgs my-alert alert-info" id="j_idt51" style="margin-top:15px;"></span><script type="text/javascript">$(document).ready(function() {
new RichFaces.ui.Message("j_idt25:j_idt29",{"forComponentId":"j_idt25:messageInput","isMessages":true} )
new RichFaces.ui.NotifyMessage("j_idt51",{"showDetail":true,"globalOnly":true,"isMessages":true} ,{"nonblocking":true,"stayTime":5000,"styleClass":"my\u002Dalert alert\u002Dinfo"} )
});
</script></body>
</html>
由于
答案 0 :(得分:1)
创建自定义资源处理程序以动态修复packed.js
文件。这个hack基于作为Liferay项目的一部分完成的工作,并在回答相同问题时描述了here。自定义资源处理代码将对jQuery.atmosphere的存在性的检查添加到packed.js文件本身。
代码已经使用Richfaces 4.3.3进行了测试。其他版本的Richfaces可能需要调整JavaScript处理代码和/或RICHFACES_PACKED_STATIC_RESOURCE
常量中引用的文件。
第1步:创建自定义资源处理程序。
CustomResourceHandler.java
package example;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.application.ResourceHandlerWrapper;
import javax.faces.application.ResourceWrapper;
import org.apache.commons.io.IOUtils;
import com.google.common.base.Charsets;
/**
* Fixes "jQuery.atmosphere is undefined" in packed.js from Richfaces when using resource optimization (packing, compression).
*
* Based on: https://developer.jboss.org/message/807297#807297
*/
public class CustomResourceHandler extends ResourceHandlerWrapper {
// Private Constants
private static final String RICHFACES_PACKED_STATIC_RESOURCE = "org.richfaces.staticResource/4.3.3.Final/Packed/packed/packed.js";
private final ResourceHandler wrapped;
public CustomResourceHandler(final ResourceHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public ResourceHandler getWrapped() {
return wrapped;
}
@Override
public Resource createResource(String resourceName, String libraryName) {
Resource r = super.createResource(resourceName, libraryName);
if (resourceName.equals(RICHFACES_PACKED_STATIC_RESOURCE)) {
return new RichfacesPackedResourceWrapper(r);
}
return r;
}
}
class RichfacesPackedResourceWrapper extends ResourceWrapper {
private final Resource wrapped;
public RichfacesPackedResourceWrapper(Resource r) {
this.wrapped = r;
}
@Override
public Resource getWrapped() {
return wrapped;
}
@Override
public InputStream getInputStream() throws IOException {
InputStream s = super.getInputStream();
String contents = fixRichFacesPackedDotJs(IOUtils.toString(s));
return new ByteArrayInputStream(contents.getBytes(Charsets.UTF_8));
}
private String fixRichFacesPackedDotJs(String javaScriptText) {
String token = "if (jQuery.atmosphere.requests.length > 0) {";
int pos = javaScriptText.indexOf(token);
if (pos > 0) {
StringBuilder buf = new StringBuilder();
buf.append(javaScriptText.substring(0, pos));
buf.append("if (!jQuery.atmosphere) { return; }; ");
buf.append(javaScriptText.substring(pos));
javaScriptText = buf.toString();
}
// jQuery.atmosphere.unsubscribe();
token = "jQuery.atmosphere.unsubscribe();";
pos = javaScriptText.indexOf(token);
if (pos > 0) {
StringBuilder buf = new StringBuilder();
buf.append(javaScriptText.substring(0, pos));
buf.append("if (!jQuery.atmosphere) { return; }; ");
buf.append(javaScriptText.substring(pos));
javaScriptText = buf.toString();
}
return javaScriptText;
}
}
第2步:请参阅faces-config.xml中的自定义资源处理程序(在<application>
下)。
<resource-handler>example.CustomResourceHandler</resource-handler>
答案 1 :(得分:0)
RichFaces已经附带了jQuery(1.8.3)和氛围,如果你包括你自己的jquery.js,可能会有冲突
如果您需要使用更高版本的jQuery,请创建META-INF / richfaces / static-resource-mappings.properties并将此行放入其中:
jquery.js=path/to/your/jquery.js
有关重新路由资源的详情,请查看here
编辑:
清理源文件:
<h:head>
并且包含jquery.js <h:head>
并包含另一个jquery.js