Search in sources :

Example 6 with ViewConfig

use of org.apache.deltaspike.core.api.config.view.ViewConfig in project deltaspike by apache.

the class ViewConfigAwareNavigationHandler method handleNavigation.

// Security checks will be performed by the view-handler provided by ds
@Override
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
    lazyInit();
    if (outcome != null && outcome.contains(".")) {
        String originalOutcome = outcome;
        if (!this.otherOutcomes.contains(outcome)) {
            // it isn't possible to support interfaces due to cdi restrictions
            if (outcome.startsWith("class ")) {
                outcome = outcome.substring(6);
            }
            ViewConfigDescriptor entry = this.viewConfigs.get(outcome);
            if (entry == null) {
                if (DefaultErrorView.class.getName().equals(originalOutcome)) {
                    entry = this.viewConfigResolver.getDefaultErrorViewConfigDescriptor();
                }
            }
            boolean allowCaching = true;
            if (entry == null) {
                Class<?> loadedClass = ClassUtils.tryToLoadClassForName(outcome);
                if (loadedClass == null) {
                    this.otherOutcomes.add(originalOutcome);
                } else if (ViewConfig.class.isAssignableFrom(loadedClass)) {
                    // a sub-classed page-config for annotating it with different view params
                    if (loadedClass.getAnnotation(View.class) == null && loadedClass.getSuperclass().getAnnotation(View.class) != null) {
                        allowCaching = false;
                        addConfiguredViewParameters(loadedClass);
                        loadedClass = loadedClass.getSuperclass();
                    }
                    entry = this.viewConfigResolver.getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
                }
            }
            if (entry != null) {
                // in case of false it has been added already
                if (allowCaching) {
                    this.viewConfigs.put(outcome, entry);
                    addConfiguredViewParameters(entry.getConfigClass());
                }
                String oldViewId = null;
                if (facesContext.getViewRoot() != null) {
                    oldViewId = facesContext.getViewRoot().getViewId();
                }
                PreViewConfigNavigateEvent navigateEvent = firePreViewConfigNavigateEvent(oldViewId, entry);
                entry = tryToUpdateEntry(entry, navigateEvent);
                if (entry != null) {
                    outcome = convertEntryToOutcome(facesContext.getExternalContext(), entry);
                }
            }
        }
    }
    this.navigationHandler.handleNavigation(facesContext, fromAction, outcome);
}
Also used : PreViewConfigNavigateEvent(org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) 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)

Example 7 with ViewConfig

use of org.apache.deltaspike.core.api.config.view.ViewConfig in project deltaspike by apache.

the class DefaultConfigNodeConverter method convert.

@Override
public ConfigDescriptor convert(ViewConfigNode node) {
    List<Annotation> mergedMetaData = mergeMetaData(node.getMetaData(), node.getInheritedMetaData());
    // e.g. replace default placeholders needed for the merge with real default values
    mergedMetaData = preProcessMetaData(mergedMetaData, node);
    Class sourceClass = node.getSource();
    if (ViewConfigUtils.isFolderConfig(sourceClass)) {
        Folder folderAnnotation = findMetaDataByType(mergedMetaData, Folder.class);
        return new DefaultFolderConfigDescriptor(folderAnnotation.name(), node.getSource(), mergedMetaData, node.getCallbackDescriptors());
    } else if (ViewConfig.class.isAssignableFrom(sourceClass)) {
        View viewAnnotation = findMetaDataByType(mergedMetaData, View.class);
        String viewId = viewAnnotation.basePath() + viewAnnotation.name() + "." + viewAnnotation.extension();
        return new DefaultViewPathConfigDescriptor(viewId, (Class<? extends ViewConfig>) node.getSource(), filterInheritedFolderMetaData(mergedMetaData), node.getCallbackDescriptors());
    } else {
        throw new IllegalStateException(node.getSource() + " isn't a valid view-config");
    }
}
Also used : ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) Folder(org.apache.deltaspike.jsf.api.config.view.Folder) View(org.apache.deltaspike.jsf.api.config.view.View) Annotation(java.lang.annotation.Annotation)

Aggregations

ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)7 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 View (org.apache.deltaspike.jsf.api.config.view.View)3 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)2 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)2 ViewConfigNode (org.apache.deltaspike.core.spi.config.view.ViewConfigNode)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationCase (javax.faces.application.NavigationCase)1 PreViewConfigNavigateEvent (org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent)1 Folder (org.apache.deltaspike.jsf.api.config.view.Folder)1 AccessDecisionState (org.apache.deltaspike.security.api.authorization.AccessDecisionState)1 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)1 Secured (org.apache.deltaspike.security.api.authorization.Secured)1 SecurityViolation (org.apache.deltaspike.security.api.authorization.SecurityViolation)1