Search in sources :

Example 21 with UIViewRoot

use of javax.faces.component.UIViewRoot 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)

Example 22 with UIViewRoot

use of javax.faces.component.UIViewRoot in project oxCore by GluuFederation.

the class FacesService method renderView.

public void renderView(String viewId) {
    final FacesContext ctx = FacesContext.getCurrentInstance();
    final ViewHandler viewHandler = ctx.getApplication().getViewHandler();
    UIViewRoot newRoot = viewHandler.createView(ctx, viewId);
    updateRenderTargets(ctx, viewId);
    ctx.setViewRoot(newRoot);
    clearViewMapIfNecessary(ctx, viewId);
    ctx.renderResponse();
}
Also used : FacesContext(javax.faces.context.FacesContext) ViewHandler(javax.faces.application.ViewHandler) UIViewRoot(javax.faces.component.UIViewRoot)

Example 23 with UIViewRoot

use of javax.faces.component.UIViewRoot in project joinfaces-bean-test by larmic.

the class FacesContextMock method replaceIn.

public FacesContextMock replaceIn(ApplicationContext applicationContext) {
    final FacesContext facesContext;
    final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    if (!beanFactory.containsBean("facesContext")) {
        facesContext = mock(FacesContext.class);
        beanFactory.registerSingleton("facesContext", facesContext);
    } else {
        facesContext = (FacesContext) beanFactory.getBean("facesContext");
    }
    final ExternalContext externalContext = mock(ExternalContext.class);
    final UIViewRoot uiViewRoot = mock(UIViewRoot.class);
    when(facesContext.getExternalContext()).thenReturn(externalContext);
    when(externalContext.getRequestParameterMap()).thenReturn(parameterMap);
    when(facesContext.getViewRoot()).thenReturn(uiViewRoot);
    when(uiViewRoot.getViewMap()).thenReturn(viewMap);
    final Field field;
    try {
        field = FacesContext.class.getDeclaredField("instance");
        field.setAccessible(true);
        final ThreadLocal<FacesContext> threadLocal = (ThreadLocal<FacesContext>) field.get(null);
        threadLocal.set(facesContext);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FacesContext(javax.faces.context.FacesContext) Field(java.lang.reflect.Field) ExternalContext(javax.faces.context.ExternalContext) UIViewRoot(javax.faces.component.UIViewRoot) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 24 with UIViewRoot

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

the class CommonHandlers method handleBareAttribute.

/**
 * If the bare attribute is found in the query string and the value is "true",
 * then add "bare=true" to the specified url string.
 * @param url
 * @return
 */
private static String handleBareAttribute(FacesContext ctx, String url) {
    // Get Page Session...
    UIViewRoot root = ctx.getViewRoot();
    Map<String, Serializable> pageSession = PageSessionResolver.getPageSession(ctx, root);
    if (pageSession == null) {
        pageSession = PageSessionResolver.createPageSession(ctx, root);
    }
    String request = (String) ctx.getExternalContext().getRequestParameterMap().get("bare");
    if (request != null) {
        // It was specified, use this.
        if (request.equalsIgnoreCase("true")) {
            url = addQueryStringParam(url, "bare", "true");
            request = "true";
        } else {
            request = "false";
        }
        pageSession.put("bare", request);
    } else {
        // Get the Page Session Map
        Object pageSessionValue = pageSession.get("bare");
        if (Boolean.TRUE.equals(pageSessionValue)) {
            url = addQueryStringParam(url, "bare", "true");
        } else {
            pageSession.put("bare", "false");
        }
    }
    return url;
}
Also used : Serializable(java.io.Serializable) UIViewRoot(javax.faces.component.UIViewRoot)

Example 25 with UIViewRoot

use of javax.faces.component.UIViewRoot in project acs-community-packaging by Alfresco.

the class FacesHelper method getFacesContextImpl.

/**
 * Return a valid FacesContext for the specific context, request and response.
 * The FacesContext can be constructor for Servlet and Portlet use.
 *
 * @param context       ServletContext or PortletContext
 * @param request       ServletRequest or PortletRequest
 * @param response      ServletReponse or PortletResponse
 *
 * @return FacesContext
 */
private static FacesContext getFacesContextImpl(Object request, Object response, Object context, String viewRoot) {
    FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    // Doesn't set this instance as the current instance of FacesContext.getCurrentInstance
    FacesContext facesContext = contextFactory.getFacesContext(context, request, response, lifecycle);
    // Set using our inner class
    InnerFacesContext.setFacesContextAsCurrent(facesContext);
    // set a new viewRoot, otherwise context.getViewRoot returns null
    if (viewRoot == null) {
        viewRoot = FacesHelper.BROWSE_VIEW_ID;
    }
    UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, viewRoot);
    facesContext.setViewRoot(view);
    return facesContext;
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesContextFactory(javax.faces.context.FacesContextFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory) Lifecycle(javax.faces.lifecycle.Lifecycle) 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