2

ViewExpiredExceptionGlassFish 3.1 で Mojarra 2.1.0 (RichFaces 4 を使用)を処理する方法について、さまざまな投稿をフォローしようとしました。しかし、私が定義したweb.xmlことは、効果があるとは言えません。フォーム ベース セキュリティを使用しており、ユーザーはコンテンツにアクセスするためにログオンする必要があります。セッションがタイムアウトしたときにGlassfish(カタリナ)がユーザーを単純なJSFページにリダイレクトし、ログインページに戻るリンクが必要です。

次のエラー メッセージが常に表示されます。

javax.faces.application.ViewExpiredException: viewId:/app_user/activity/List.xhtml - View /app_user/activity/List.xhtml could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:202)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:113)

ユーザー セッションがタイムアウトしたときにユーザーをリダイレクトし、サーバー ログに例外をトラップできるのは誰ですか?

こんにちは、クリス。

レイアウト.xhtml

<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:rich="http://richfaces.org/rich">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <!-- Had no effect
        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
        <meta http-equiv="Pragma" content="no-cache" />
        <meta http-equiv="Expires" content="0" />
        -->      
        <h:outputStylesheet name="css/default.css"/>
        <h:outputStylesheet name="css/cssLayout.css"/>

        <title>
            <h:outputText value="Partner Tapestry - " /> <ui:insert name="title">Browser Title</ui:insert>
        </title>
    </h:head>

    <h:body>
        <div id="top" >
            <ui:insert name="top">Top Default</ui:insert>
        </div>

        <div id="messages">
            <rich:messages id="messagePanel"/>
        </div>

        <div id="content">
            <ui:insert name="content">Content Default</ui:insert>
        </div>
    </h:body>
</html>

web.xml

...
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>
        2
    </session-timeout>
</session-config>
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/faces/resources/sessionExpired.xhtml</location>
</error-page>
...

login.xhtml

<ui:composition template="/resources/masterLayout.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:a4j="http://richfaces.org/a4j">

    <ui:define name="title">
        <h:outputText value="Login"></h:outputText>
    </ui:define>
    <ui:define name="top">
        <h:outputText value="Welcome" />
    </ui:define>

    <ui:define name="content">         
        <h:form>
            <h:panelGrid columns="3">
                <h:outputLabel for="username" value="Username" />
                <h:inputText id="username" value="#{userController.userAuthentication}" />
                <br />
                <h:outputLabel for="password" value="Password" />
                <h:inputSecret id="password" value="#{userController.passwordAuthentication}" />
                <br />
                <h:outputText value=" " />
                <a4j:commandButton action="#{userController.login()}" value="Login"/>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

最後にsessionExpire.xhtml

<ui:composition template="/resources/masterLayout.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:a4j="http://richfaces.org/a4j">

    <ui:define name="title">
        <h:outputText value="Session Exired"></h:outputText>
    </ui:define>
    <ui:define name="top">
        <h:outputText value="Session expired, please login again" />
    </ui:define>

    <ui:define name="content"> 
        <h:form>           
            <a4j:commandLink action="/resources/login?faces-redirect=true" value="Login" />
        </h:form>
    </ui:define>
</ui:composition>
4

2 に答える 2

4

あなたのアプローチは、同期 POST リクエストに対して完全にうまく機能するはずです。ただし、非同期 (ajax) POST 要求を使用しています。jsf.ajax.addOnErrorajax リクエストの例外は、JavaScript の init 関数またはカスタムのいずれかで処理する必要がありますExceptionHandler

こちらもご覧ください

于 2011-09-22T14:26:38.493 に答える
1

Solved the problem by following this link on implementing a ExceptionHandlerFactory. A nice solution where you can have an exception navigation rule, but maybe a bit long. Thanks for the help @BalusC.

于 2011-09-23T09:51:23.573 に答える