Search in sources :

Example 1 with LifecycleFactory

use of javax.faces.lifecycle.LifecycleFactory 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)

Example 2 with LifecycleFactory

use of javax.faces.lifecycle.LifecycleFactory in project deltaspike by apache.

the class MockedJsf2TestContainer method initLifecycle.

protected void initLifecycle() {
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    this.lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
}
Also used : MockLifecycleFactory(org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory)

Example 3 with LifecycleFactory

use of javax.faces.lifecycle.LifecycleFactory 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)

Example 4 with LifecycleFactory

use of javax.faces.lifecycle.LifecycleFactory in project ma-core-public by infiniteautomation.

the class FacesExtensionFilter method doFilter.

/* (non-Javadoc)
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    // Either set a private member
    // servletContext = filterConfig.getServletContext();
    // in your filter init() method or set it here like this:
    // ServletContext servletContext =
    // ((HttpServletRequest) request).getSession().getServletContext();
    // Note that the above line would fail if you are using any other
    // protocol than http
    // Doesn't set this instance as the current instance of
    // FacesContext.getCurrentInstance
    FacesContext facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle);
    // Set using our inner class
    InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
    try {
        // call the filter chain
        chain.doFilter(request, response);
    } finally {
        // Clean up after ourselves as FacesContext is a ThreadLocal object
        try {
            facesContext.release();
        } catch (IllegalStateException ex) {
            // Perhaps the FacesContext has already been released?
            log.warn("Double release of faces context?", ex);
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesContextFactory(javax.faces.context.FacesContextFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory) Lifecycle(javax.faces.lifecycle.Lifecycle)

Aggregations

LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)4 FacesContext (javax.faces.context.FacesContext)3 FacesContextFactory (javax.faces.context.FacesContextFactory)3 UIViewRoot (javax.faces.component.UIViewRoot)2 Lifecycle (javax.faces.lifecycle.Lifecycle)2 PrintWriter (java.io.PrintWriter)1 Application (javax.faces.application.Application)1 ViewHandler (javax.faces.application.ViewHandler)1 ServletContext (javax.servlet.ServletContext)1 MockLifecycleFactory (org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory)1