0

我有一个带有 frameowrks JSF (Primefaces)、Spring、Spring Security、PrettyFaces 和 Mybatis 的 webapp。Webapp 有一个登录页面作为索引页面。第一次部署 webapp 并且我尝试登录时发生 IllegalArgumentException 或 ViewExpiredException 取决于 jsf 版本。这些异常分别发生在 jsf 版本 2.1.3 和 2.1.0

错误消息 IllegalArgumentException

java.lang.IllegalArgumentException: null source
    java.util.EventObject.<init>(EventObject.java:38)
    javax.faces.event.SystemEvent.<init>(SystemEvent.java:71)
    javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:73)
    javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:73)
    com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:271)
    com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:257)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)

错误信息 ViewExpiredException

javax.faces.application.ViewExpiredException: viewId:/login.xhtml - No se pudo restablecer la vista /login.xhtml.
    com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:202)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:113)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)

虽然我可以在 faces-config 文件中添加 exception-handler-factory 来解决这个问题,但我很惊讶会发生这些异常,因为据我所知,这只会在会话过期时发生,但如果我只是部署应用程序,怎么可能会话到期?

PD:Primefaces 3.5、Spring 3.1.1、Spring Security 3.1.3、PrettyFaces 3.3.3、Mybatis 3.1.1 Tomcat 6.0.10

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" 
    id="WebApp_ID" version="2.5">

  <display-name>Archetype Created Web Application</display-name>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</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.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
  </context-param>
  <context-param>
    <description>indicar si estamos en desarrollo, en producción</description>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>Para poder utilizar comentarios xml</description>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
  <context-param>
    <param-name>prettyFacesConfig</param-name>
    <param-value>/WEB-INF/pretty-config.xml</param-value>
  </context-param>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
  </context-param>
  <context-param>
      <param-name>primefaces.THEME</param-name>
      <param-value>none</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>login.xhtml</welcome-file>
  </welcome-file-list>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <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>*.xhtml</url-pattern>
  </servlet-mapping>

  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
  <listener>
    <listener-class>
      org.springframework.security.web.session.HttpSessionEventPublisher
    </listener-class>
  </listener>

  <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>

  <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>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>
  <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>
        org.primefaces.webapp.filter.FileUploadFilter
    </filter-class>
     <init-param>
        <param-name>thresholdSize</param-name>
        <param-value>2097152</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

</web-app>
4

1 回答 1

0

我解决了我的问题。在我的登录页面中,我使用对话框组件。我更改了面板组件并且允许发生异常

登录页面(第一版)

<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:sec="http://www.springframework.org/security/tags"
      template="/resources/template/template.xhtml">

      <ui:define name="header"></ui:define>
      <ui:define name="menu"></ui:define>
      <ui:define name="content">
            <h:form id="formLogin" prependId="false">

                  <p:dialog id="dlgLogin" header="SYSTEM" closable="false" resizable="false" draggable="false" visible="true"
                        width="480" height="340" position="center" styleClass="dlgNoTitle">

                        <p:messages id="messages" autoUpdate="true" closable="true" />

                        <p:graphicImage id="imgLogin" value="/resources/images/login1.jpg"
                                               style=" left: 25px; position: relative; margin-top:10px" />
                        <p:panel styleClass="pnlNoTitle">
                             <h:panelGrid columns="2">

                                   <h:outputLabel for="j_username" value="Usuario:" 
                                         style="font-weight: bold; color: grey; font-family:arial, sans-serif;"/>
                                   <p:inputText value="#{loginController.user.username}" id="j_username" required="true" label="Usuario" />
                                   <h:outputLabel for="j_password" value="Password:" style="font-weight: bold; color: grey; font-family:arial, sans-serif;"/>
                                   <p:password value="#{loginController.user.password}" id="j_password" required="true" label="Password" />
                                   <p:commandButton id="loginButton" value="Ingresar" icon="ui-icon-key" action="#{loginController.login}" ajax="false"
                                         update="messages"/>

                             </h:panelGrid>
                        </p:panel>

                  </p:dialog>

            </h:form>


      </ui:define>
</ui:composition>

登录页面(第二版)

<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:sec="http://www.springframework.org/security/tags"
      template="/resources/template/template.xhtml">

    <ui:define name="header"></ui:define>
    <ui:define name="menu"></ui:define>
    <ui:define name="content">

        <div style="vertical-align: middle; position: relative; padding-top: 100px">
        <h:form id="formLogin" prependId="false">

            <p:panel id="pnlLogin" 
                style="width: 480px; height: 340px; margin: auto auto auto auto; ">
                <p:messages id="messages" autoUpdate="true" closable="true" /> 

                <p:graphicImage id="imgLogin" value="/resources/images/login1.jpg"
                                style=" left: 25px; position: relative; margin-top:10px" />
                <p:panel styleClass="pnlNoTitle">
                <div align="center">
                    <h:panelGrid columns="2">

                        <h:outputLabel for="j_username" value="Usuario:"  
                            style="font-weight: bold; color: grey; font-family:arial, sans-serif;"/>
                        <p:inputText value="#{loginController.user.username}" id="j_username" required="true" label="Usuario" />
                        <h:outputLabel for="j_password" value="Password:" style="font-weight: bold; color: grey; font-family:arial, sans-serif;"/>
                        <p:password value="#{loginController.user.password}" id="j_password" required="true" label="Password" />

                        <p:commandButton id="loginButton" value="Ingresar" icon="ui-icon-key" action="#{loginController.login}" ajax="false" 
                            update="messages"/>

                    </h:panelGrid>
                </div>
                </p:panel>

            </p:panel>

        </h:form>
        </div>


    </ui:define>
</ui:composition>

现在,问题是为什么对话组件会发生这种情况:)

于 2013-07-23T05:19:48.357 回答