Search in sources :

Example 1 with ViewConfigDescriptor

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

the class ViewConfigTest method testMetaDataInheritanceInViewConfig.

@Test
public void testMetaDataInheritanceInViewConfig() {
    this.viewConfigExtension.addPageDefinition(Pages.class);
    this.viewConfigExtension.addPageDefinition(Pages.Admin.class);
    this.viewConfigExtension.addPageDefinition(Pages.Admin.Index.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ConfigDescriptor<?> configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.class);
    Assert.assertNotNull(configDescriptor);
    Assert.assertNotNull(configDescriptor.getConfigClass());
    Assert.assertEquals(Pages.class, configDescriptor.getConfigClass());
    Assert.assertNotNull(configDescriptor.getMetaData());
    Assert.assertEquals(1, configDescriptor.getMetaData().size());
    Assert.assertEquals(1, configDescriptor.getMetaData(Folder.class).size());
    Assert.assertEquals("/pages/", configDescriptor.getMetaData(Folder.class).iterator().next().name());
    configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.Admin.class);
    Assert.assertNotNull(configDescriptor);
    Assert.assertNotNull(configDescriptor.getConfigClass());
    Assert.assertEquals(Pages.Admin.class, configDescriptor.getConfigClass());
    Assert.assertNotNull(configDescriptor.getMetaData());
    Assert.assertEquals(1, configDescriptor.getMetaData().size());
    Assert.assertEquals(1, configDescriptor.getMetaData(Folder.class).size());
    Assert.assertEquals("/pages/admin/", configDescriptor.getMetaData(Folder.class).iterator().next().name());
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Admin.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertEquals("/pages/admin/index.xhtml", viewConfigDescriptor.getViewId());
    Assert.assertEquals(Pages.Admin.Index.class, viewConfigDescriptor.getConfigClass());
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(View.NavigationMode.FORWARD, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("index", viewConfigDescriptor.getMetaData(View.class).iterator().next().name());
    Assert.assertEquals("xhtml", viewConfigDescriptor.getMetaData(View.class).iterator().next().extension());
    Assert.assertEquals("/pages/admin/", viewConfigDescriptor.getMetaData(View.class).iterator().next().basePath());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 2 with ViewConfigDescriptor

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

the class ViewConfigTest method testViewConfigWithStereotypeMetaData.

@Test
public void testViewConfigWithStereotypeMetaData() {
    this.viewConfigExtension.addPageDefinition(Pages.Home.class);
    this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Home.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(2, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(MyView.class).size());
    Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.INCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("landing page", viewConfigDescriptor.getMetaData(MyView.class).iterator().next().description());
    viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(2, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(MyView.class).size());
    Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("public content", viewConfigDescriptor.getMetaData(MyView.class).iterator().next().description());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 3 with ViewConfigDescriptor

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

the class ViewConfigTest method testViewConfigWithStereotypeMetaData.

@Test
public void testViewConfigWithStereotypeMetaData() {
    this.viewConfigExtension.addPageDefinition(Pages.Home.class);
    this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Home.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
    Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.INCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
    Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 4 with ViewConfigDescriptor

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

the class DefaultViewConfigResolver method initCaches.

protected void initCaches() {
    //folders
    Map<String, ConfigDescriptor> folderPathMapping = new HashMap<String, ConfigDescriptor>();
    for (ConfigDescriptor folderConfigDescriptor : this.folderDefinitionToViewDefinitionEntryMapping.values()) {
        if (folderPathMapping.containsKey(folderConfigDescriptor.toString())) {
            throw new IllegalStateException("Duplicated config for the same folder configured. See: " + folderPathMapping.get(folderConfigDescriptor.toString()).getConfigClass().getName() + " and " + folderConfigDescriptor.getConfigClass().getName());
        }
        folderPathMapping.put(folderConfigDescriptor.getPath(), folderConfigDescriptor);
    }
    this.folderPathToViewDefinitionEntryMapping = Collections.unmodifiableMap(folderPathMapping);
    //pages
    Map<String, ViewConfigDescriptor> viewPathMapping = new HashMap<String, ViewConfigDescriptor>();
    for (ViewConfigDescriptor pageConfigDescriptor : this.viewDefinitionToViewDefinitionEntryMapping.values()) {
        if (viewPathMapping.containsKey(pageConfigDescriptor.getViewId())) {
            throw new IllegalStateException("Duplicated config for the same page configured. See: " + viewPathMapping.get(pageConfigDescriptor.getViewId()).getConfigClass().getName() + " and " + pageConfigDescriptor.getConfigClass().getName());
        }
        viewPathMapping.put(pageConfigDescriptor.getPath(), pageConfigDescriptor);
    }
    this.viewPathToViewDefinitionEntryMapping = Collections.unmodifiableMap(viewPathMapping);
}
Also used : HashMap(java.util.HashMap) ConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)

Example 5 with ViewConfigDescriptor

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

the class DeltaSpikePhaseListener method processPreRenderView.

private void processPreRenderView(FacesContext facesContext) {
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    if (uiViewRoot != null) {
        ViewConfigDescriptor viewDefinitionEntry = this.viewConfigResolver.getViewConfigDescriptor(uiViewRoot.getViewId());
        ViewControllerUtils.executeViewControllerCallback(viewDefinitionEntry, PreRenderView.class);
    }
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)44 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)37 Test (org.junit.Test)31 View (org.apache.deltaspike.jsf.api.config.view.View)5 Method (java.lang.reflect.Method)3 UIViewRoot (javax.faces.component.UIViewRoot)3 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)3 ViewControllerRef (org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef)3 ConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)2 NavigationCase (javax.faces.application.NavigationCase)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 PreRenderView (org.apache.deltaspike.core.api.config.view.controller.PreRenderView)2 PreViewConfigNavigateEvent (org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent)2 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)2 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 List (java.util.List)1