PrimeFaces 3.0 + Mojarra 2.1.6 javascript ajax 包 jsf.ajax.* 不可用 - ViewExpiredException

发布于 2025-01-02 01:06:40 字数 6775 浏览 0 评论 0 原文

我试图调查这个问题,但根本没有找到解决方案。我使用带有分页的 primefaces 数据表。我按照 Ed Burns 在他的博客中建议的那样编写了 viewexpiredexception 错误的异常处理程序,但是当与 ajax 提交(例如数据表页面导航)结合使用时,不会处理 vee 上的页面重定向。我在这里使用了 BalusC 建议的解决方案 JSF 状态栏/连接状态信息 但是chrome 说它缺少 jsf.ajax.* javascript 命名空间。该页面运行在tomcat 7.0.22上,启动时没有错误/警告,后端基于spring和mybatis。这是 web.xml,

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Discontinui</display-name>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <session-config>
        <session-timeout>2</session-timeout>
    </session-config>
</web-app>

这是 faces-config.xml

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

    <application>  
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>  
    </application> 

    <factory>
      <exception-handler-factory>it.dipvvf.vi.app.common.ViewExpiredExceptionExceptionHandlerFactory</exception-handler-factory>
  </factory>
</faces-config>

,这是 index.xhtml 页面:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Prova</title>
    <script type="text/javascript">
    var statusUpdate = function statusUpdate(data) {
        var statusArea = document.getElementById("statusArea");
        var text = statusArea.value;
        text = text + "Name: "+data.source.id;
        if (data.type === "event") {
            text = text +" Event: "+data.name+"\n";
        } else {  // otherwise, it's an error
            text = text + " Error: "+data.name+"\n";
        }
        statusArea.value = text;
    };

    // Setup the statusUpdate function to hear all events on the page
    alert("0");
    jsf.ajax.addOnEvent(statusUpdate);
    alert("1");
    jsf.ajax.addOnError(statusUpdate);
    alert("2");
    </script>
</h:head>
<h:body>
    <h:form>
Selezionare il tipo di accesso:<br />
        <p:selectOneMenu id="somAccessMode" value="#{accessMode.mode}">
            <f:selectItem itemValue="#{accessMode.ufficioPersonale}"
                itemLabel="Ufficio Personale" />
            <f:selectItem itemValue="#{accessMode.capoTurno}"
                itemLabel="Capo Turno" />
        </p:selectOneMenu>
        <br />
        <p:commandButton id="bEnter" value="Entra"
            action="#{accessMode.onEntraClick}" update="growl" />
        <br />
        <p:dataTable var="nominativo" value="#{accessMode.elencoNominativi}" paginator="true" rows="1"  
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15">
            <p:column>
                <f:facet name="header">  
                    Cognome  
                </f:facet>
                <h:outputText value="#{nominativo.cognome}" />
            </p:column>

            <p:column>
                <f:facet name="header">  
                    Nome  
                </f:facet>
                <h:outputText value="#{nominativo.nome}" />
            </p:column>

            <p:column>
                <f:facet name="header">  
                    Data Iscrizione  
                </f:facet>
                <h:outputText value="#{nominativo.iscrizione}">
                    <f:convertDateTime pattern="dd-MM-yyyy" />
                </h:outputText>
            </p:column>
        </p:dataTable>
        <hr />
        <br />
        <!-- <p:messages showDetail="true" autoUpdate="true"/>   -->
        <p:growl id="growl" showDetail="true" sticky="true" />
        <h3>Status:</h3>
        <textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
    </h:form>
</h:body>
</html>

我已经放置了超出测试所需的内容。警报(“1”)和“2”不显示,并且 jsf.ajax.add... 在浏览器中引发错误。如果我在 chrome 中查看并生成页面,我看不到任何捆绑到 mojarra 包中的 jsf.js。缺陷在哪里?

感谢大家,并对篇幅表示抱歉!

I've tried to investigate the problem but haven't found solution at all. I use primefaces datatable with pagination. I wrote and exception handler for viewexpiredexception error as Ed Burns suggested in his blog but when used in combiation with ajax submits (eg. datatable page navigation) the page redirection on vee is not handled. I used the solution suggested by BalusC here JSF Status bar / connection status information but chrome says it's missing jsf.ajax.* javascript namespace. The page runs on tomcat 7.0.22 with no error/warning at startup and back-end is based on spring and mybatis. Here is the web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Discontinui</display-name>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <session-config>
        <session-timeout>2</session-timeout>
    </session-config>
</web-app>

here is the faces-config.xml

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

    <application>  
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>  
    </application> 

    <factory>
      <exception-handler-factory>it.dipvvf.vi.app.common.ViewExpiredExceptionExceptionHandlerFactory</exception-handler-factory>
  </factory>
</faces-config>

and here is the index.xhtml page:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Prova</title>
    <script type="text/javascript">
    var statusUpdate = function statusUpdate(data) {
        var statusArea = document.getElementById("statusArea");
        var text = statusArea.value;
        text = text + "Name: "+data.source.id;
        if (data.type === "event") {
            text = text +" Event: "+data.name+"\n";
        } else {  // otherwise, it's an error
            text = text + " Error: "+data.name+"\n";
        }
        statusArea.value = text;
    };

    // Setup the statusUpdate function to hear all events on the page
    alert("0");
    jsf.ajax.addOnEvent(statusUpdate);
    alert("1");
    jsf.ajax.addOnError(statusUpdate);
    alert("2");
    </script>
</h:head>
<h:body>
    <h:form>
Selezionare il tipo di accesso:<br />
        <p:selectOneMenu id="somAccessMode" value="#{accessMode.mode}">
            <f:selectItem itemValue="#{accessMode.ufficioPersonale}"
                itemLabel="Ufficio Personale" />
            <f:selectItem itemValue="#{accessMode.capoTurno}"
                itemLabel="Capo Turno" />
        </p:selectOneMenu>
        <br />
        <p:commandButton id="bEnter" value="Entra"
            action="#{accessMode.onEntraClick}" update="growl" />
        <br />
        <p:dataTable var="nominativo" value="#{accessMode.elencoNominativi}" paginator="true" rows="1"  
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15">
            <p:column>
                <f:facet name="header">  
                    Cognome  
                </f:facet>
                <h:outputText value="#{nominativo.cognome}" />
            </p:column>

            <p:column>
                <f:facet name="header">  
                    Nome  
                </f:facet>
                <h:outputText value="#{nominativo.nome}" />
            </p:column>

            <p:column>
                <f:facet name="header">  
                    Data Iscrizione  
                </f:facet>
                <h:outputText value="#{nominativo.iscrizione}">
                    <f:convertDateTime pattern="dd-MM-yyyy" />
                </h:outputText>
            </p:column>
        </p:dataTable>
        <hr />
        <br />
        <!-- <p:messages showDetail="true" autoUpdate="true"/>   -->
        <p:growl id="growl" showDetail="true" sticky="true" />
        <h3>Status:</h3>
        <textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
    </h:form>
</h:body>
</html>

I've put more than needed just for tests. The alert("1") and "2" does not show and jsf.ajax.add... raise error in browser. If I look and generated page in chrome I can't see any inclusion of jsf.js bundled into mojarra package. Where is the flaw?

Thanks to anyone and sorry for the lenght!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青萝楚歌 2025-01-09 01:06:40

问题是您正在使用 primefaces 组件 (
试试这个:

>

primefaces 注册自己的回调,任何 jsf.ajax.* 将无法从 primefaces 组件执行。

The problem is that you are using primefaces components (<p:commandButton)
<p:commandButton id="bEnter" value="Entra" action="#{accessMode.onEntraClick}" update="growl"/>

try this:
<h:commandButton id="bEnter" value="Entra" action="#{accessMode.onEntraClick}">
<f:ajax execute="@form" render="growl"/>
</h:commandButton>

primefaces register their own callbacks and any jsf.ajax.* won't be able to be executed from primefaces components.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文