0

セッションをチェックするフィルターがあります。私のフィルター:

public class FilterLogin implements Filter{

    FilterConfig fc;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        fc = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        HttpSession session = req.getSession(true);

        if (session.getAttribute("loginMB") == null) {
            resp.sendRedirect("/home.xhtml");
        } else {
            chain.doFilter(request, response);
        }  
    }

    @Override
    public void destroy() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}

web.xml:

<filter>
    <filter-name>filter</filter-name>
    <filter-class>pl.ePrzychodnia.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>filter</filter-name>
    <url-pattern>/protected/*</url-pattern>
</filter-mapping> 
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/home.xhtml</location>
</error-page>

セッションの有効期限が切れたら、home.xhtml サイトに移動する必要があります。しかし、セッションが期限切れになり、ページのナビゲーション メニューをクリックしたい場合、コンポーネントはクリックに反応しません... Primefaces を使用しないと、すべてが正しく動作します。プロジェクトでプライムフェイスを使用すると、このエラーが発生します。原因は何ですか?

グローバル例外ハンドラを使用しようとしましたが、少し問題があります。このサイトhttp://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/からクラスをコピーし ます

クラス CustomExceptionHandler で編集:

try {

                //log error ?
                log.log(Level.SEVERE, "Critical Exception!", t);

                //redirect error page
                requestMap.put("exceptionMessage", t.getMessage());
                nav.handleNavigation(fc, null, "/home");
                fc.renderResponse();

                // remove the comment below if you want to report the error in a jsf error message
                //JsfUtil.addErrorMessage(t.getMessage());

            } 

私は変更します:nav.handleNavigation(fc, null, "/error");nav.handleNavigation(fc, null, "/home");

しかし、セッションがタイムアウトすると、home.xhtmlページにリダイレクトされず、クリックしたときにのみページに移動し、エラーの例があります:

SEVERE: Critical Exception!
javax.faces.application.ViewExpiredException: viewId:/protected/admin/about.xhtml - View /protected/admin/about.xhtml could not be restored.

セッションの有効期限が切れたときにページについての参照をクリックしたとき。home.xhtml の代わりに不完全な about.xhtml ページが表示される

4

1 に答える 1

1

ほとんどの場合、マネージド Bean に対して ajax 呼び出しを行います。そのため、Web xml でエラー ナビゲーションが機能しません。onerrorアクションが ajax リクエストとして呼び出された場合、エラーは JavaScript コールバックに送信されます。

サーバー側でエラーを処理する場合は、アプリケーションにグローバル例外ハンドラーを追加できます。JSFチュートリアルを使用してグローバル例外処理を追加することは、従うのに適しています。

さらに、OmniFaces の FullAjaxExceptionHandler 機能を使用できます

于 2013-07-10T15:38:14.247 に答える