當我的會話在我的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 {
有沒有人知道如何解決這個問題。
見編輯答案。 –