为什么在登录页面的jsf-spring webapp中会出现ViewExpiredException / IllegalArgumentException?

时间:2013-06-19 21:51:23

标签: login primefaces illegalargumentexception viewexpiredexception

我有一个带有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>

1 个答案:

答案 0 :(得分:0)

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

登录页面(第1版)

<?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>

登录页面(第2版)

<?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>

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