当我的会话在我的Java EE 7,JSF Web应用程序中过期时。在JSF 2中的AJAX请求中的ViewExpiredException上的重定向
我在ajax请求中得到ViewExpiredException。
我想重定向到一个页面,它向用户显示会话已过期。
我试过浏览谷歌和stackoverflow的解决方案,但我did not没有任何运气,让它与我想要它的工作。
UPDATE:
我尝试使用login_submit按钮时,该解决方案张贴@Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request
它没有工作,在我的登录页面。
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="./../templates/login_template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.login_title}"/>
</ui:define>
<ui:define name="content">
<h:outputText escape="false" value="#{bundle.login_message}"/>
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="#{bundle.login_username}"/>
<p:inputText id="username" type="text" value="#{authBean.username}" label="username"/>
<h:outputLabel for="password" value="#{bundle.login_password}"/>
<p:inputText id="password" type="password" value="#{authBean.password}" label="password"/>
<h:outputText value="#{bundle.login_invalid_password}" rendered="#{!authBean.validPassword and authBean.validUsername}"/>
<h:outputText value="#{bundle.login_invalid_username}" rendered="#{!authBean.validUsername}"/>
<p:commandButton value="#{bundle.login_submit}" action="#{authBean.doLogin}"/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
不过,这并不与此JSF的XHTML页面是安全网页上工作,登录页面是一个公共页面。例如,下面的XHTML是安全网页上:
<p:commandButton styleClass="button #{chartBean.isViewButtonActive('MONTH')}" update="dataChart dataTable @form" value="#{bundle.performance_year}" action="#{chartBean.changeModel('MONTH')}" />
这确实一个AJAX POST请求,但被我的@WebFilter逮住。 (它也发生在Primefaces中的selectOneMenu)这个过滤器检查用户是否登录,如果没有登录,它将它们重定向到登录页面。但出于某种原因,使用上面给出的示例按钮,它也会被@WebFilter捕获,并且ajax请求将作为@WebFilter中指定的响应重定向获取。它不会被ExceptionHandler捕获。 @WebFilter仅适用于安全页面,请参见下文。
@WebFilter(
filterName = "AuthorizationFilter",
urlPatterns = {"/secure/*"},
dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD}
)
public class AuthorizationFilter implements Filter {
有没有人知道如何解决这个问题。
见编辑答案。 –