简体   繁体   English

<a4j:loadScript>用于加载JQuery脚本抛出异常

[英]<a4j:loadScript> for Loading JQuery Script Throwing Exception

I am trying to use JQuery in my JSF page embedded with RF3.3.1.. Here is my code snippet:- 我试图在嵌入RF3.3.1。的JSF页面中使用JQuery。这是我的代码段:-

<%@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. 不仅如此,我的JQuery本身还没有运行...被告知要使用.js文件。当我这样做时,它引发了异常...我将jQuery-1.7.1.js文件包含在了我的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. 我从jQuery网站复制了脚本代码,并在Eclipse IDE中创建了一个新的js文件。 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. 将整个脚本代码复制到新的js文件中,并将其命名为jQuery-1.7.1。这是我用于Jquery的文件。 Is there anything wrong here? 这里有什么问题吗?

Except jQuery-1.7.1.js I have no other js file related to JQuery. 除了jQuery-1.7.1.js,我没有其他与JQuery相关的js文件。

Please guide me... 请指导我...

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> . 看来<a4j:loadScript>元素需要在<f:view>内部。

See here for a similar issue. 有关类似问题,请参见此处

if nothing else works you can use richfaces built in support for jquery without including the script 如果没有其他效果,则可以使用内置的支持jquery的richfaces而不包含脚本

http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_jQuery.html http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_jQuery.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM