jsf-2faces-configfacescontext

How to access the navigation-case of the faces config from a Java class


I have this situation, where I have to access the entire faces config from a managed beans. More specifically, I need to access the list of navigation cases, that were specified in the faces-config and cycle through them. Is there any way to get them?

I saw that NavigationCase has some good methods that reveal some useful information .. Question is now, how to get a list of these NavigationCase


Solution

  • Based on the Tags you have specified in your question, i can say that you are using JSF 2, so you can use the ConfigurableNavigationHandler to get what you are looking for.

    Use the ConfigurableNavigationHandler#getNavigationCases() to get a Map of Navigation cases, you can get more informations about that method from it's Javadocs:

    Return a Map<String, Set<NavigationCase>> where the keys are values and the values are Set where each element in the Set is a NavigationCase that applies to that .

    This is an example for invoking that method:

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

    In case you already knew the name of the page you want to navigate to, you can simply use that example (assuming your page file is next.xhtml):

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

    See also: