2014-04-22 33 views
0

我正在使用登錄過濾器並已成功實施它們。但現在,如果用戶嘗試查看頁面,我需要通過在地址欄中直接提供(頁面的URL)來顯示錯誤消息,指出「需要驗證」。未通過身份驗證時發送「身份驗證消息」,會話超時時發送「會話已過期」

此外,我需要顯示錯誤消息,如「會話已過期」,當會話超時。 後者的實現(如所有人所建議的),使用過濾器重定向到登錄或index.xhtml已結束。但我想到顯示錯誤信息。

任何幫助嗎? 在此先感謝

+0

後你已經嘗試了 – Makky

+0

喜makky,我已經打了web.xml文件和指定的錯誤頁面,e xception類型(查看過期例外)像許多其他類型。 – murthi

回答

0

這裏見我的回答:https://stackoverflow.com/a/23217445/1453701 在你的情況,而不是使用閃光燈或會話範圍,你應該使用URL參數讓鑑於知道它應該在@PostConstruct

添加的FacesMessage在你豆你可以把:

@PostConstruct 
public void init() { 
    String showMessage = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("showMessage"); 
    if ("true".equals(showMessage)) { 
     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Authentication Required", "place your detailed message here")); 
    } 
} 
+0

hi tushee,謝謝你的迴應。但由於即時通訊新的jsf可以顯示一些代碼添加facesMessage在@postconstruct和使用url參數 – murthi

+0

我已經編輯我的答案與例@PostConstruct方法 – Tushee

+0

正如你所說,當會話過期時,我附加以下內容httpResponse.sendRedirect(httpRequest.getContextPath()+「/faces/login.xhtml?showMessage=true」)在servlet過濾器中,但在我的bean中,當我使用FacesContext.getCurrentInstance()。getExternalContext()。getReternalParameterMap ().get(「showMessage」),存儲在字符串showMessage中的值爲空!任何想法 ? – murthi

0

您可以嘗試類似onload檢查的頁面正文調用遠程命令。在remotecommand的行動本身,你可以指定Bean的方法,做了檢查:

<h:body id="page_body" onload="isConnected();"> 
    <h:form > 
     <p:remoteCommand name="isConnected" update=":page_body" autoRun="false" action="#{myBean.checkIfLoggedIn()}"/> 
    </h:form> 
    .................. 
</h:body>