问题
I am trying to use JQuery in my JSF page embedded with RF3.3.1.. Here is my code snippet:-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JQuery Effects</title>
<script type="text/javascript" ></script>
<a4j:loadScript src="resource://jquery.js"/>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function()
{
$j("#formId\\:showLinkId").click(function()
{
alert("Hide Done");
});
});
</script>
</head>
<body>
<f:view>
<h:form id="formId">
<rich:panel header="Jquery" style="position: relative; width: 350px;">
<h:commandButton id="showLinkId" value="Click Here"/>
<h:outputLabel id="success" value="DONE" ></h:outputLabel>
</rich:panel>
</h:form>
</f:view>
</body>
</html>
However when I get the following exception on server when this page is loaded:-
15:16:27,062 ERROR [STDERR] org.apache.jasper.JasperException: An exception occurred processing JSP page /hssViewStore/Test.jsp
10: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
11: <title>JQuery Effects</title>
12: <script type="text/javascript" ></script>
13: <a4j:loadScript src="resource://jquery.js"/>
14: <script>
15: var $j = jQuery.noConflict();
16: $j(document).ready(function()
Stacktrace:
15:16:27,062 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
15:16:27,062 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
15:16:27,062 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
15:16:27,062 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
15:16:27,062 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
15:16:27,062 ERROR [STDERR] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
15:16:27,062 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
15:16:27,062 ERROR [STDERR] at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:542)
15:16:27,078 ERROR [STDERR] at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandling
15:16:27,078 ERROR [STDERR] at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java
15:16:27,078 ERROR [STDERR] at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.jav
15:16:27,078 ERROR [STDERR] at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
15:16:27,078 ERROR [STDERR] at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
15:16:27,078 ERROR [STDERR] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
15:16:27,078 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
15:16:27,078 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:1
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstabl
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstabli
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
15:16:27,078 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
15:16:27,078 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
15:16:27,078 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
15:16:27,078 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:6
15:16:27,078 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
15:16:27,078 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
15:16:27,078 ERROR [STDERR] Caused by: java.lang.ClassCastException: org.ajax4jsf.component.AjaxViewRoot cannot be cast to org.a
15:16:27,078 ERROR [STDERR] at org.ajax4jsf.taglib.html.jsp.LoadScriptTag.setProperties(LoadScriptTag.java:57)
15:16:27,078 ERROR [STDERR] at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:614
15:16:27,078 ERROR [STDERR] at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1142)
15:16:27,078 ERROR [STDERR] at org.apache.jsp.hssViewStore.Test_jsp._jspx_meth_a4j_005floadScript_005f0(Test_jsp.java:133)
15:16:27,078 ERROR [STDERR] at org.apache.jsp.hssViewStore.Test_jsp._jspService(Test_jsp.java:85)
15:16:27,078 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
15:16:27,078 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
15:16:27,078 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
15:16:27,093 ERROR [STDERR] ... 49 more
NOT ONLY this my JQuery itself is not running...I was told to include the .js file using .When I did that it threw the exception... I included the jQuery-1.7.1.js file in my web-inf.
This is what i have done to include the file:-
I copied the script code from jQuery website and created a new js file in Eclipse IDE. Copied the entire script code in new js file and names it as jQuery-1.7.1.js.This is the file I am using for Jquery. Is there anything wrong here?
Except jQuery-1.7.1.js I have no other js file related to JQuery.
Please guide me...
回答1:
Even though this is an older question, I thought I'd post my findings for those of us who happened upon this looking for an answer.
It appears that the <a4j:loadScript>
element needs to be inside <f:view>
.
See here for a similar issue.
回答2:
if nothing else works you can use richfaces built in support for jquery without including the script
http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_jQuery.html
来源:https://stackoverflow.com/questions/8455710/a4jloadscript-for-loading-jquery-script-throwing-exception