我对 JSF 会话处理有疑问:起初我每次都得到viewExpiredException
:
javax.faces.application.ViewExpiredException: viewId:/anyForm.jsf - View /anyForm.jsf could not be restored.
所以我在我的文件中添加了以下代码web.xml
:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/index.jsf?reason=expired</location>
</error-page>
以及我的index.jsf
文件中的以下内容(也有一些表格和输入):
<h:outputText value="#{messages.session_expired}"
rendered="#{param.reason == 'expired'}" />
每当我现在超时时,我都会重定向到index.jsf
并显示文本,但是如果我在输入中输入一个值并按下表单的提交按钮,我仍然会重定向到我的index.jsf
. 所以,我陷入了一个循环。我也尝试过这样的事情:
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
由于我阅读index.jsf
然后自动创建一个新会话。但是,这根本没有帮助我。如果我遇到(循环)超时并更改输入值并提交表单(我使用的是 primefaces“微调器”输入),我也会得到这个异常:
javax.servlet.ServletException: Index: 1, Size: 1
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.util.ArrayList.RangeCheck(ArrayList.java:547)
java.util.ArrayList.get(ArrayList.java:322)
javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
javax.faces.component.UIInput.restoreState(UIInput.java:1411)
com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:276)
com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)
javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
javax.faces.component.UIForm.visitTree(UIForm.java:344)
javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:263)
com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:452)
com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
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)