Search in sources :

Example 36 with UIViewRoot

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

the class JsfContainerTest 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());
    UIViewRoot uiViewRoot = new UIViewRoot();
    uiViewRoot.setViewId("/viewId");
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
    Assert.assertEquals("/viewId", FacesContext.getCurrentInstance().getViewRoot().getViewId());
    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"));
    Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
    if (identityHashCode == null) {
        identityHashCode = System.identityHashCode(applicationMap);
    } else {
        Assert.assertSame(identityHashCode, System.identityHashCode(applicationMap));
    }
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) Map(java.util.Map) Test(org.junit.Test)

Example 37 with UIViewRoot

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

the class JsfContainerTest method secondTest.

@Test
public void secondTest() {
    Assert.assertEquals(0, requestScopedBean.getCount());
    requestScopedBean.increaseCount();
    Assert.assertEquals(1, requestScopedBean.getCount());
    Assert.assertEquals(0, sessionScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(1, sessionScopedBean.getCount());
    UIViewRoot uiViewRoot = new UIViewRoot();
    uiViewRoot.setViewId("/viewId");
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
    Assert.assertEquals("/viewId", FacesContext.getCurrentInstance().getViewRoot().getViewId());
    uiViewRoot.setViewId("/test2.xhtml");
    uiViewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertEquals("/test2.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", "2");
    Assert.assertEquals("2", FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
    Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
    if (identityHashCode == null) {
        identityHashCode = System.identityHashCode(applicationMap);
    } else {
        Assert.assertSame(identityHashCode, System.identityHashCode(applicationMap));
    }
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) Map(java.util.Map) Test(org.junit.Test)

Example 38 with UIViewRoot

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

the class MockedJsfContainerTest method secondTest.

@Test
public void secondTest() {
    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("/test2.xhtml");
    uiViewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertEquals("/test2.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", "2");
    Assert.assertEquals("2", FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test)

Example 39 with UIViewRoot

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

the class DefaultErrorViewAwareExceptionHandlerWrapper method handle.

@Override
public void handle() throws FacesException {
    lazyInit();
    Iterator<ExceptionQueuedEvent> exceptionQueuedEventIterator = getUnhandledExceptionQueuedEvents().iterator();
    while (exceptionQueuedEventIterator.hasNext()) {
        ExceptionQueuedEventContext exceptionQueuedEventContext = (ExceptionQueuedEventContext) exceptionQueuedEventIterator.next().getSource();
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) Throwable throwable = exceptionQueuedEventContext.getException();
        String viewId = null;
        if (!isExceptionToHandle(throwable)) {
            continue;
        }
        FacesContext facesContext = exceptionQueuedEventContext.getContext();
        Flash flash = facesContext.getExternalContext().getFlash();
        if (throwable instanceof ViewExpiredException) {
            viewId = ((ViewExpiredException) throwable).getViewId();
        } else if (throwable instanceof ContextNotActiveException) {
            // (it's recorded below - see flash.put(throwable.getClass().getName(), throwable);)
            if (flash.containsKey(ContextNotActiveException.class.getName())) {
                // TODO show it in case of project-stage development
                break;
            }
            if (facesContext.getViewRoot() != null) {
                viewId = facesContext.getViewRoot().getViewId();
            } else {
                viewId = BeanProvider.getContextualReference(ViewConfigResolver.class).getDefaultErrorViewConfigDescriptor().getViewId();
            }
        }
        if (viewId != null) {
            UIViewRoot uiViewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);
            if (uiViewRoot == null) {
                continue;
            }
            if (facesContext.isProjectStage(javax.faces.application.ProjectStage.Development) || ProjectStageProducer.getInstance().getProjectStage() == ProjectStage.Development || ProjectStageProducer.getInstance().getProjectStage() instanceof TestStage) {
                throwable.printStackTrace();
            }
            facesContext.setViewRoot(uiViewRoot);
            exceptionQueuedEventIterator.remove();
            // record the current exception -> to check it at the next call or to use it on the error-page
            flash.put(throwable.getClass().getName(), throwable);
            flash.keep(throwable.getClass().getName());
            this.viewNavigationHandler.navigateTo(DefaultErrorView.class);
            break;
        }
    }
    this.wrapped.handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) ViewExpiredException(javax.faces.application.ViewExpiredException) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) Flash(javax.faces.context.Flash) UIViewRoot(javax.faces.component.UIViewRoot) TestStage(org.apache.deltaspike.core.api.projectstage.TestStage)

Example 40 with UIViewRoot

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

the class DeltaSpikePhaseListener method processPostRenderView.

private void processPostRenderView(FacesContext facesContext) {
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    if (uiViewRoot != null) {
        ViewConfigDescriptor viewDefinitionEntry = this.viewConfigResolver.getViewConfigDescriptor(uiViewRoot.getViewId());
        ViewControllerUtils.executeViewControllerCallback(viewDefinitionEntry, PostRenderView.class);
    }
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) 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