2012-07-17 104 views
0

我使用JSF2有一個應用程序時,JBoss 6.1和縫3.我想要做這樣的事情:JSF2導航問題

如果用戶試圖訪問應用程序,未通過身份驗證

,他應該被引導到登錄頁面。如果用戶已經登錄,即使他輸入登錄網址,他也應該被定向到主頁,而不是再次登錄。所以我把它放在faces-config.xml上

<navigation-rule> 
    <navigation-rule> 
    <from-view-id>/login.xhtml</from-view-id> 
    <navigation-case> 
     <if>#{identity.loggedIn}</if> 
     <to-view-id>/user/search.xhtml</to-view-id> 
     <redirect> 
      <view-param> 
       <name>cid</name> 
       <value>#{userBean.conversation.id}</value> 
      </view-param> 
     </redirect> 
    </navigation-case> 
</navigation-rule> 
    <from-view-id>*</from-view-id> 
    <navigation-case> 
     <from-action>#{identity.login}</from-action> 
     <if>#{identity.loggedIn}</if> 
     <to-view-id>/user/search.xhtml</to-view-id> 
     <redirect> 
      <view-param> 
       <name>cid</name> 
       <value>#{userBean.conversation.id}</value> 
      </view-param> 
     </redirect> 
    </navigation-case> 
    <navigation-case> 
     <from-action>#{identity.login}</from-action> 
     <from-outcome>failed</from-outcome> 
     <to-view-id>/denied.xhtml</to-view-id> 
    </navigation-case> 
    <navigation-case> 
     <from-outcome>login</from-outcome> 
     <to-view-id>/login.xhtml</to-view-id> 
     <redirect /> 
    </navigation-case> 
</navigation-rule> 

但是第一條規則不起作用。如果用戶使用login.xhtml鍵入網址,則他會保留在頁面上。我需要他重定向。我怎樣才能做到這一點?

感謝

凱利

回答

0

我認爲你必須使用縫面模塊。它與煤層安全相結合。 你應該看看this part of the doc

在我的項目,我不使用任何導航規則和我的網頁配置對象看起來是這樣的:

@ViewConfig 
public interface Pages { 
    static enum Configuration { 
     @ViewPattern("/pages/*") 
     @LoggedIn 
     PRIVATE, 

     @UrlMapping(pattern="/pages/home.xhtml") 
     @ViewPattern("/login.xhtml") 
     @FacesRedirect(false) 
     LOGIN, 

     @ViewPattern("/*") 
     @FacesRedirect 
     @LoginView("/login.xhtml") 
     ALL; 

    } 

} 

This other question還幫我做你所需要的。