Search in sources :

Example 16 with UIViewRoot

use of javax.faces.component.UIViewRoot in project tutorials by eugenp.

the class PhaseListenerBean method beforeListener.

public void beforeListener(PhaseEvent event) {
    if (!event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
        return;
    }
    UIViewRoot root = event.getFacesContext().getViewRoot();
    boolean showNewFeature = showNewFeatureForIp(event);
    processComponentTree(root, event, showNewFeature);
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot)

Example 17 with UIViewRoot

use of javax.faces.component.UIViewRoot in project skeleton-commons by skeleton-software-community.

the class ViewScope method get.

/**
 * {@inheritedDoc}
 */
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    if (viewRoot != null) {
        Map<String, Object> viewMap = viewRoot.getViewMap();
        if (viewMap.containsKey(name)) {
            return viewMap.get(name);
        } else {
            Object object = objectFactory.getObject();
            viewMap.put(name, object);
            return object;
        }
    } else {
        return null;
    }
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot)

Example 18 with UIViewRoot

use of javax.faces.component.UIViewRoot in project deltaspike by apache.

the class SecurityAwareViewHandler method createView.

@Override
public UIViewRoot createView(FacesContext context, String viewId) {
    UIViewRoot result = this.wrapped.createView(context, viewId);
    if (!this.activated) {
        return result;
    }
    if (this.securityModuleActivated == null) {
        lazyInit();
    }
    if (!this.securityModuleActivated) {
        return result;
    }
    UIViewRoot originalViewRoot = context.getViewRoot();
    Map<String, Object> viewMap = null;
    if (originalViewRoot != null) {
        Map<String, Object> originalViewMap = originalViewRoot.getViewMap(false);
        if (originalViewMap != null && !originalViewMap.isEmpty()) {
            viewMap = new HashMap<String, Object>();
            viewMap.putAll(originalViewMap);
        }
    }
    // workaround for PreDestroyViewMapEvent which would be caused by the security check
    deactivatePreDestroyViewMapEvent(context);
    // we have to use it as current view if an AccessDecisionVoter uses the JSF API to check access to the view-id
    context.setViewRoot(result);
    try {
        ViewRootAccessHandler viewRootAccessHandler = BeanProvider.getContextualReference(ViewRootAccessHandler.class);
        viewRootAccessHandler.checkAccessTo(result);
    } catch (ErrorViewAwareAccessDeniedException accessDeniedException) {
        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
        ViewConfigDescriptor errorViewDescriptor = viewConfigResolver.getViewConfigDescriptor(accessDeniedException.getErrorView());
        try {
            if (errorViewDescriptor != null && View.NavigationMode.REDIRECT == errorViewDescriptor.getMetaData(View.class).iterator().next().navigation() && /*always available*/
            BeanProvider.getContextualReference(JsfModuleConfig.class).isAlwaysUseNavigationHandlerOnSecurityViolation()) {
                SecurityUtils.tryToHandleSecurityViolation(accessDeniedException);
            } else {
                SecurityUtils.handleSecurityViolationWithoutNavigation(accessDeniedException);
            }
        } finally {
            broadcastAccessDeniedException(accessDeniedException);
        }
        if (errorViewDescriptor != null) {
            return this.wrapped.createView(context, errorViewDescriptor.getViewId());
        } else {
            // the previous page (including the error message)
            if (!context.isPostback() && context.getViewRoot() != null) {
                context.getViewRoot().setViewId(null);
            }
        }
        // security exception without error-view
        throw accessDeniedException;
    } finally {
        activatePreDestroyViewMapEvent(context);
        if (originalViewRoot != null) {
            context.setViewRoot(originalViewRoot);
            if (viewMap != null) {
                originalViewRoot.getViewMap().putAll(viewMap);
            }
        }
    }
    return result;
}
Also used : JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) ErrorViewAwareAccessDeniedException(org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) UIViewRoot(javax.faces.component.UIViewRoot) View(org.apache.deltaspike.jsf.api.config.view.View) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 19 with UIViewRoot

use of javax.faces.component.UIViewRoot in project deltaspike by apache.

the class MockedJsfContainerTest method firstTest.

@Test
public void firstTest() {
    Assert.assertEquals(0, requestScopedBean.getCount());
    requestScopedBean.increaseCount();
    Assert.assertEquals(1, requestScopedBean.getCount());
    Assert.assertEquals(0, sessionScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(1, sessionScopedBean.getCount());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
    Assert.assertEquals("/viewId", FacesContext.getCurrentInstance().getViewRoot().getViewId());
    UIViewRoot uiViewRoot = new UIViewRoot();
    uiViewRoot.setViewId("/test1.xhtml");
    uiViewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertEquals("/test1.xhtml", FacesContext.getCurrentInstance().getViewRoot().getViewId());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getExternalContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getApplication());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getELContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getPartialViewContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getRenderKit());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getExceptionHandler());
    Assert.assertNull(FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("test", "1");
    Assert.assertEquals("1", FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test)

Example 20 with UIViewRoot

use of javax.faces.component.UIViewRoot in project deltaspike by apache.

the class MockedJsf2TestContainer method initDefaultView.

protected void initDefaultView() {
    UIViewRoot root = new UIViewRoot();
    root.setViewId("/viewId");
    root.setLocale(getLocale());
    root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    this.facesContext.setViewRoot(root);
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

UIViewRoot (javax.faces.component.UIViewRoot)41 FacesContext (javax.faces.context.FacesContext)18 Test (org.junit.Test)10 ViewHandler (javax.faces.application.ViewHandler)8 Locale (java.util.Locale)6 ResourceBundle (java.util.ResourceBundle)4 Application (javax.faces.application.Application)3 UIComponent (javax.faces.component.UIComponent)3 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Map (java.util.Map)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContextFactory (javax.faces.context.FacesContextFactory)2 PreDestroyViewMapEvent (javax.faces.event.PreDestroyViewMapEvent)2 LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)2 ServletContext (javax.servlet.ServletContext)2 NonNull (org.springframework.lang.NonNull)2 Handler (com.sun.jsftemplating.annotation.Handler)1 ModuleException (it.vige.rubia.ModuleException)1 ToHTMLConfig (it.vige.rubia.format.render.bbcodehtml.ToHTMLConfig)1