2015-02-08 87 views
1

我有這種情況,我必須從託管bean訪問整個面部配置。更具體地說,我需要訪問在faces-config中指定的導航案例列表並循環遍歷它們。 有什麼辦法讓他們?如何從Java類訪問faces配置的導航案例

我看到NavigationCase有透露一些有用的信息。問題是現在,如何讓基於你已經在你的問題中指定的標籤,這些NavigationCase

回答

1

名單,我可以說,一些好的方法您正在使用JSF 2,因此您可以使用ConfigurableNavigationHandler來獲取您要查找的內容。

使用ConfigurableNavigationHandler#getNavigationCases()得到的導航案件Map,你可以得到更多的信息有關方法從它的Javadocs

返回Map<String, Set<NavigationCase>>密鑰是 值和值設置在那裏 各Set中的元素是一個適用於該 的NavigationCase。

這是調用該方法的例子:

FacesContext context = FacesContext.getCurrentInstance(); 
ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); 
Map<String,Set<NavigationCase>> navigationCases = navigationHandler.getNavigationCases(); 

如果你已經知道你要導航,你可以簡單地使用例如頁面的名稱(假設你的頁面文件next.xhtml):

FacesContext context = FacesContext.getCurrentInstance(); 
ConfigurableNavigationHandler navigationHandler= (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); 
navigationHandler.performNavigation("next"); 

參見:

0

試試這個代碼:

FacesContext ctxt = FacesContext.getCurrentInstance(); 
ConfigurableNavigationHandler configNavHandler = (ConfigurableNavigationHandler)ctxt.getApplication().getNavigationHandler(); 
NavigationCase navCase = configNavHandler.getNavigationCase(ctxt,null,"Page"); 
String toViewId = navCase.getToViewId(ctxt);