Search in sources :

Example 1 with NavigationCase

use of javax.faces.application.NavigationCase in project deltaspike by apache.

the class DeltaSpikeNavigationHandler method getNavigationCase.

@Override
public NavigationCase getNavigationCase(FacesContext context, String action, String outcome) {
    if (this.wrapped instanceof ConfigurableNavigationHandler) {
        if (!this.activated) {
            return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
        }
        if (action == null && outcome != null && outcome.contains(".") && outcome.startsWith("class ") && !otherOutcomes.contains(outcome)) {
            String originalOutcome = outcome;
            NavigationCase navigationCase = this.viewConfigBasedNavigationCaseCache.get(originalOutcome);
            if (navigationCase != null) {
                return navigationCase;
            }
            outcome = outcome.substring(6);
            ViewConfigDescriptor entry = null;
            if (DefaultErrorView.class.getName().equals(originalOutcome)) {
                ViewConfigResolver viewConfigResolver = JsfUtils.getViewConfigResolver();
                entry = viewConfigResolver.getDefaultErrorViewConfigDescriptor();
            }
            if (entry == null) {
                Object loadedClass = ClassUtils.tryToLoadClassForName(outcome);
                if (loadedClass == null) {
                    this.otherOutcomes.add(originalOutcome);
                } else if (ViewConfig.class.isAssignableFrom((Class) loadedClass)) {
                    entry = JsfUtils.getViewConfigResolver().getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
                }
            }
            if (entry != null) {
                View.NavigationMode navigationMode = entry.getMetaData(View.class).iterator().next().navigation();
                navigationCase = new NavigationCase("*", null, null, null, entry.getViewId(), null, View.NavigationMode.REDIRECT.equals(navigationMode), false);
                this.viewConfigBasedNavigationCaseCache.put(originalOutcome, navigationCase);
                return navigationCase;
            }
        }
        return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
    }
    return null;
}
Also used : DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) NavigationCase(javax.faces.application.NavigationCase) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) View(org.apache.deltaspike.jsf.api.config.view.View) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) ConfigurableNavigationHandler(javax.faces.application.ConfigurableNavigationHandler) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 2 with NavigationCase

use of javax.faces.application.NavigationCase in project deltaspike by apache.

the class NavigationCaseMapWrapper method createViewConfigBasedNavigationCases.

private Map<String, Set<NavigationCase>> createViewConfigBasedNavigationCases(boolean allowParameters) {
    Map<String, Set<NavigationCase>> result;
    if (this.wrapped instanceof ConfigurableNavigationHandler) {
        result = new DelegatingMap((ConfigurableNavigationHandler) this.wrapped);
    } else {
        LOG.warning("the wrapped navigation-handler doesn't extend " + ConfigurableNavigationHandler.class.getName() + ". therefore std. navigation-rules might not work correctly with mojarra");
        result = new HashMap<String, Set<NavigationCase>>();
    }
    Collection<ViewConfigDescriptor> viewConfigDescriptors = BeanProvider.getContextualReference(ViewConfigResolver.class).getViewConfigDescriptors();
    if (!viewConfigDescriptors.isEmpty()) {
        Set<NavigationCase> navigationCase = new HashSet<NavigationCase>();
        Map<String, List<String>> parameters = null;
        if (allowParameters) {
            parameters = resolveParameters();
        }
        boolean includeParameters;
        for (ViewConfigDescriptor entry : viewConfigDescriptors) {
            View viewMetaData = entry.getMetaData(View.class).iterator().next();
            includeParameters = View.ViewParameterMode.INCLUDE.equals(viewMetaData.viewParams());
            navigationCase.add(new NavigationCase("*", null, null, null, entry.getViewId(), includeParameters ? parameters : null, View.NavigationMode.REDIRECT.equals(viewMetaData.navigation()), includeParameters));
            result.put(entry.getViewId(), navigationCase);
        }
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) View(org.apache.deltaspike.jsf.api.config.view.View) ConfigurableNavigationHandler(javax.faces.application.ConfigurableNavigationHandler) NavigationCase(javax.faces.application.NavigationCase) List(java.util.List) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) HashSet(java.util.HashSet)

Aggregations

ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)2 NavigationCase (javax.faces.application.NavigationCase)2 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)2 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)2 View (org.apache.deltaspike.jsf.api.config.view.View)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)1 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)1