3

OmniFaces 機能の使用について助けが必要です。

FacesExceptionFilter を使用して、例外が発生したときにユーザーをエラー ページにリダイレクトしようとしています。

次の web.xml 構成があります

<?xml version="1.0" encoding="UTF-8"?>

<display-name>xxxxx</display-name>

<session-config>
    <session-timeout>1</session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>pages/secured/main.xhtml</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</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.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-application-context.xml</param-value>
</context-param>

<context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>2</param-value>
</context-param>

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>mytheme</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.SEPARATOR_CHAR</param-name>
    <param-value>_</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>com.bdo.corpsoa.utilities.security.listeners.impl.CorpSoaSessionListener</listener-class>
</listener>

<filter>
    <filter-name>facesExceptionFilter</filter-name>
    <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>facesExceptionFilter</filter-name>
    <servlet-name>facesServlet</servlet-name>
</filter-mapping>


<context-param>
    <param-name>org.omnifaces.FACES_VIEWS_SCAN_PATH</param-name>
    <param-value>/*.xhtml</param-value>
</context-param>

<context-param>
    <param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
    <param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
</context-param>

<!-- <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> 
    </filter-mapping> -->

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/WEB-INF/pages/errors/viewExpired.xhtml</location>
</error-page>

<error-page>
    <exception-type>java.lang.RuntimeException</exception-type>
    <location>/WEB-INF/pages/errors/unHandled.xhtml</location>
</error-page>

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>

<error-page>
    <exception-type>java.io.FileNotFoundException</exception-type>
    <location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>

ただし、例外が発生すると、ユーザーはデフォルトの 500 エラー ページにリダイレクトされます。

リダイレクトは、エラー ページを WEB-INF フォルダー /WEB-INF/pages/errors/pageNotFound.xhtml から移動した場合にのみ機能します --> /pages/errors/pageNotFound.xhtml

ただし、これは、エラー ページに直接アクセスできるようになったことを意味します。しかし、Omnifaces のショーケースでは、これが可能になるはずです。何が欠けているのかわかりません助けてください...

これは、WEB-INF のエラー ページが可能であることを示す Omnifaces ショーケースの web.xml です。

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" 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-app_3_0.xsd" metadata-complete="false"

    <display-name>OmniFaces Showcase</display-name>


    <!-- Standard JSF settings. -->

    <context-param>
            <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
            <param-value>65535</param-value> <!-- 64KB. -->
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>0</param-value> <!-- Should be -1 for production. -->
    </context-param>
    <context-param>
            <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
            <param-value>/WEB-INF/showcase.taglib.xml</param-value>
    </context-param>
    <context-param>
            <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
            <param-value>true</param-value>
    </context-param>


    <!-- Mojarra/RI specific settings. -->

    <context-param>
            <param-name>com.sun.faces.defaultResourceMaxAge</param-name>
            <param-value>3628800000</param-value> <!-- 6 weeks. -->
    </context-param>


    <!-- MyFaces specific settings. -->

    <context-param>
            <param-name>org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES</param-name>
            <param-value>3628800000</param-value> <!-- 6 weeks. -->
    </context-param>
    <context-param>
            <!--
                    MyFaces and Mojarra don't agree on the default setting for actually serializing state
                    in the session as opposed to just storing a reference. Mojarra's default is false, but
                    can be switched to true. MyFaces' default is true, and can be switched to false, which
                    we thus do below. See http://arjan-tijms.omnifaces.org/p/jsf-22.html#1127
             -->
            <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
            <param-value>false</param-value>
    </context-param>


    <!-- OmniFaces specific settings. -->

    <context-param>
            <param-name>org.omnifaces.CACHE_SETTING_SESSION_MAX_CAPACITY</param-name>
            <param-value>6</param-value>
    </context-param>
    <context-param>
            <!--
                    All files in the 3 paths defined below will be scanned and made available
                    as extensionless JSF views. Since no explicit extension is given for scanning,
                    these paths should contain ONLY JSF (Facelets) files.
             -->
            <param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
            <param-value>/showcase,/etc,/demo</param-value>
    </context-param>
    <context-param>
            <!--
                    Redirects the faces views scanned /showcase/[PAGE].xhtml to /[PAGE].
                    A 404 would normally be preferred (and this is thus the default), but the showcase app
                    already has published /showcase/[PAGE].xhtml
            -->
            <param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
            <param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
    </context-param>


    <!-- Servlets and filters. -->

    <servlet>
            <servlet-name>facesServlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
            <servlet-name>facesServlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>characterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
            <filter-name>facesExceptionFilter</filter-name>
            <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>facesExceptionFilter</filter-name>
            <servlet-name>facesServlet</servlet-name>
    </filter-mapping>

    <filter>
            <filter-name>gzipResponseFilter</filter-name>
            <filter-class>org.omnifaces.filter.GzipResponseFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>gzipResponseFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>ERROR</dispatcher>
    </filter-mapping>


    <!-- Welcome files, error pages and mime types. -->
    
    <session-config>
            <cookie-config>
                    <http-only>true</http-only>
            </cookie-config>
            <tracking-mode>COOKIE</tracking-mode>
    </session-config>

    <welcome-file-list>
            <!--
                    Note that an extension is used here, since the index file resides within the
                    root which has not been configured for FacesViews scanning.
            -->
            <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <error-page>
            <exception-type>javax.faces.application.ViewExpiredException</exception-type>
            <location>/WEB-INF/errorpages/expired.xhtml</location>
    </error-page>
    <error-page>
            <exception-type>java.sql.SQLException</exception-type>
            <location>/WEB-INF/errorpages/database.xhtml</location>
    </error-page>
    <error-page>
            <exception-type>java.lang.RuntimeException</exception-type>
            <location>/WEB-INF/errorpages/bug.xhtml</location>
    </error-page>
    <error-page>
            <error-code>500</error-code>
            <location>/WEB-INF/errorpages/500.xhtml</location>
    </error-page>
    <error-page>
            <error-code>404</error-code>
            <location>/WEB-INF/errorpages/404.xhtml</location>
    </error-page>

    <mime-mapping>
            <!--
                    Silence WebLogic's annoying "JSF1091: No mime type could be found for file" warning.
            -->
            <extension>xhtml</extension>
            <mime-type>text/html</mime-type>
    </mime-mapping>

概要

  1. WEB-INF の外にある場合、エラー ページへのリダイレクトが機能します。
  2. ショーケースは、それが可能であることを示しています。
  3. 私は助けが必要です....

お時間をいただきありがとうございます

編集

「WEB-INF外ならエラーページへのリダイレクトが効く」ようです。常に真であるとは限りません。

WEB-INF外の場合、このエラーページが表示されます

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

<h:body>
    <h1>#{"XXXXXXXX"}</h1>

</h:body>
</html>

WEB-INF外でもこのエラーページは表示されません。これにより、デフォルトの 404 ページが表示されます

 <?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:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
    
    <h:body>
        <h1>ZZZZZZZZZ</h1>
    
    </h:body>
    </html>
4

1 に答える 1

0

jsf ページに EL 式または jsf コンポーネントを配置すると、FacesExceptionFilter が実際に機能しているようです。

何らかの理由で、このエラー ページは機能せず、デフォルトの 404 ページが生成されます。

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

<h:body>
    <h1>ZZZZZZZZZ</h1>
</h:body>
</html>

ただし、このエラー ページは機能します。

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

<h:body>
    <h1>#{"XXXXXXXX"}</h1>
</h:body>
</html>
于 2013-07-12T06:15:14.167 に答える