Search in sources :

Example 1 with UIViewRoot

use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.

the class EffortsBean method resetComponentsTree.

protected void resetComponentsTree() {
    Application application = facesContext.getApplication();
    ViewHandler viewHandler = application.getViewHandler();
    UIViewRoot viewRoot = viewHandler.createView(facesContext, facesContext.getViewRoot().getViewId());
    facesContext.setViewRoot(viewRoot);
}
Also used : ViewHandler(javax.faces.application.ViewHandler) Application(javax.faces.application.Application) UIViewRoot(javax.faces.component.UIViewRoot)

Example 2 with UIViewRoot

use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.

the class ExceptionHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    FacesContextMocker.mockFacesContext();
    ExternalContext externalContext = mock(ExternalContext.class);
    when(FacesContext.getCurrentInstance().getExternalContext()).thenReturn(externalContext);
    servletContext = mock(ServletContext.class);
    when(FacesContext.getCurrentInstance().getExternalContext().getContext()).thenReturn(servletContext);
    InputStream input = new FileInputStream(ERROR_MESSAGES_PROPERTIES_PATH);
    when(servletContext.getResourceAsStream(anyString())).thenReturn(input);
    UIViewRoot viewRoot = mock(UIViewRoot.class);
    when(FacesContext.getCurrentInstance().getViewRoot()).thenReturn(viewRoot);
    when(viewRoot.getChildren()).thenReturn(new ArrayList<>());
    wrappedExceptionHandler = mock(javax.faces.context.ExceptionHandler.class);
}
Also used : ExternalContext(javax.faces.context.ExternalContext) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ServletContext(javax.servlet.ServletContext) UIViewRoot(javax.faces.component.UIViewRoot) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 3 with UIViewRoot

use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.

the class EffortsBeanTest method testResetComponentsTree.

@Test
public void testResetComponentsTree() throws Exception {
    FacesContext facesContext = createMock(FacesContext.class);
    Application application = createMock(Application.class);
    ViewHandler viewHandler = createMock(ViewHandler.class);
    UIViewRoot viewRoot = createMock(UIViewRoot.class);
    String viewId = "viewId";
    setField(effortsBean, "facesContext", facesContext);
    expect(facesContext.getApplication()).andReturn(application);
    expect(application.getViewHandler()).andReturn(viewHandler);
    expect(facesContext.getViewRoot()).andReturn(viewRoot);
    expect(viewRoot.getViewId()).andReturn(viewId);
    expect(viewHandler.createView(facesContext, viewId)).andReturn(viewRoot);
    facesContext.setViewRoot(viewRoot);
    replay(facesContext, application, viewHandler, viewRoot);
    effortsBean.resetComponentsTree();
    verify(facesContext, application, viewHandler, viewRoot);
}
Also used : FacesContext(javax.faces.context.FacesContext) ViewHandler(javax.faces.application.ViewHandler) Application(javax.faces.application.Application) UIViewRoot(javax.faces.component.UIViewRoot) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with UIViewRoot

use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.

the class WebCachedInterceptorTest method testGetContextProperties_forViewScope.

@Test
public void testGetContextProperties_forViewScope() {
    Map<String, Object> contextProperties = new HashMap<String, Object>();
    UIViewRoot viewRoot = createMock(UIViewRoot.class);
    expect(facesContextMock.getViewRoot()).andReturn(viewRoot);
    expect(viewRoot.getViewMap()).andReturn(contextProperties);
    replay(facesContextMock, viewRoot);
    Map<String, Object> actual = interceptor.getContextProperties(Scope.VIEW_SCOPED);
    verify(facesContextMock, viewRoot);
    assertEquals(contextProperties, actual);
}
Also used : HashMap(java.util.HashMap) UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test)

Example 5 with UIViewRoot

use of javax.faces.component.UIViewRoot in project Payara by payara.

the class JSFTestServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    ServletContext context = getServletContext();
    FacesContext facesContext = facesContextFactory.getFacesContext(context, request, response, lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE));
    Application application = facesContext.getApplication();
    ViewHandler viewHandler = application.getViewHandler();
    UIViewRoot viewRoot = viewHandler.createView(facesContext, null);
    facesContext.setViewRoot(viewRoot);
    PrintWriter pw = response.getWriter();
    pw.println("Created viewRoot " + viewRoot);
    pw.flush();
    pw.close();
}
Also used : FacesContext(javax.faces.context.FacesContext) ViewHandler(javax.faces.application.ViewHandler) FacesContextFactory(javax.faces.context.FacesContextFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory) ServletContext(javax.servlet.ServletContext) Application(javax.faces.application.Application) UIViewRoot(javax.faces.component.UIViewRoot) PrintWriter(java.io.PrintWriter)

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