Search in sources :

Example 1 with LifecycleFactory

use of jakarta.faces.lifecycle.LifecycleFactory in project myfaces by apache.

the class FacesServlet method init.

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("init begin");
    }
    _servletConfig = servletConfig;
    _facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    // Javadoc says: Lifecycle instance is shared across multiple simultaneous requests, it must be implemented in a
    // thread-safe manner.
    // So we can acquire it here once:
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    _lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
    if (log.isLoggable(Level.FINEST)) {
        log.finest("init end");
    }
}
Also used : LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory)

Example 2 with LifecycleFactory

use of jakarta.faces.lifecycle.LifecycleFactory in project myfaces by apache.

the class UIViewRoot method createEvent.

private PhaseEvent createEvent(FacesContext context, PhaseId phaseId) {
    if (_lifecycle == null) {
        LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
        String id = context.getExternalContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
        if (id == null) {
            id = LifecycleFactory.DEFAULT_LIFECYCLE;
        }
        _lifecycle = factory.getLifecycle(id);
    }
    return new PhaseEvent(context, phaseId, _lifecycle);
}
Also used : PhaseEvent(jakarta.faces.event.PhaseEvent) LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory)

Example 3 with LifecycleFactory

use of jakarta.faces.lifecycle.LifecycleFactory in project mojarra by eclipse-ee4j.

the class DefaultActionResponseHandler method getDefaultLifecycle.

/**
 * Get the default lifecycle.
 *
 * <p>
 * FIXME - This method lazily gets the default Lifecycle as FactoryFinder is
 * not properly re-entrant. We should be able to initialize the
 * defaultLifecycle variable in the constructor of this class.
 * </p>
 *
 * @return the default lifecycle.
 */
private synchronized Lifecycle getDefaultLifecycle() {
    if (defaultLifecycle == null) {
        LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
        defaultLifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    }
    return defaultLifecycle;
}
Also used : LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory)

Example 4 with LifecycleFactory

use of jakarta.faces.lifecycle.LifecycleFactory in project mojarra by eclipse-ee4j.

the class LifecycleConfigProcessor method process.

// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
    LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    for (int i = 0; i < documentInfos.length; i++) {
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, format("Processing lifecycle elements for document: ''{0}''", documentInfos[i].getSourceURI()));
        }
        Document document = documentInfos[i].getDocument();
        String namespace = document.getDocumentElement().getNamespaceURI();
        NodeList lifecycles = document.getElementsByTagNameNS(namespace, LIFECYCLE);
        if (lifecycles != null) {
            for (int c = 0, csize = lifecycles.getLength(); c < csize; c++) {
                Node lifecyleNode = lifecycles.item(c);
                if (lifecyleNode.getNodeType() == Node.ELEMENT_NODE) {
                    NodeList listeners = ((Element) lifecyleNode).getElementsByTagNameNS(namespace, PHASE_LISTENER);
                    addPhaseListeners(servletContext, facesContext, factory, listeners);
                }
            }
        }
    }
}
Also used : LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 5 with LifecycleFactory

use of jakarta.faces.lifecycle.LifecycleFactory in project mojarra by eclipse-ee4j.

the class JUnitFacesTestCaseBase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // Set up Servlet API Objects
    servletContext = new MockServletContext();
    servletContext.addInitParameter("appParamName", "appParamValue");
    servletContext.setAttribute("appScopeName", "appScopeValue");
    config = new MockServletConfig(servletContext);
    session = new MockHttpSession();
    session.setAttribute("sesScopeName", "sesScopeValue");
    request = new MockHttpServletRequest(session);
    request.setAttribute("reqScopeName", "reqScopeValue");
    response = new MockHttpServletResponse();
    // Set up Faces API Objects
    FactoryFinder.releaseFactories();
    Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class<?>[]) null);
    reInitializeFactoryManager.setAccessible(true);
    reInitializeFactoryManager.invoke(null, (Object[]) null);
    // Create something to stand-in as the InitFacesContext
    new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
    FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory");
    FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.mock.MockLifecycleFactory");
    FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, "com.sun.faces.mock.MockApplicationFactory");
    FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory");
    FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    lifecycle = (MockLifecycle) lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    facesContext = (MockFacesContext) fcFactory.getFacesContext(servletContext, request, response, lifecycle);
    externalContext = (MockExternalContext) facesContext.getExternalContext();
    Map map = new HashMap();
    externalContext.setRequestParameterMap(map);
    ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    application = (MockApplication) applicationFactory.getApplication();
    facesContext.setApplication(application);
}
Also used : MockFacesContext(com.sun.faces.mock.MockFacesContext) MockLifecycle(com.sun.faces.mock.MockLifecycle) MockExternalContext(com.sun.faces.mock.MockExternalContext) HashMap(java.util.HashMap) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) FacesContextFactory(jakarta.faces.context.FacesContextFactory) LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) MockServletConfig(com.sun.faces.mock.MockServletConfig) Method(java.lang.reflect.Method) MockServletContext(com.sun.faces.mock.MockServletContext) MockHttpSession(com.sun.faces.mock.MockHttpSession) ApplicationFactory(jakarta.faces.application.ApplicationFactory) HashMap(java.util.HashMap) Map(java.util.Map) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse)

Aggregations

LifecycleFactory (jakarta.faces.lifecycle.LifecycleFactory)33 Lifecycle (jakarta.faces.lifecycle.Lifecycle)12 PrintWriter (java.io.PrintWriter)11 FacesContext (jakarta.faces.context.FacesContext)8 FacesContextFactory (jakarta.faces.context.FacesContextFactory)8 PhaseEvent (jakarta.faces.event.PhaseEvent)4 ServletException (jakarta.servlet.ServletException)4 FacesException (jakarta.faces.FacesException)3 ApplicationFactory (jakarta.faces.application.ApplicationFactory)3 PhaseListener (jakarta.faces.event.PhaseListener)3 IOException (java.io.IOException)3 MockHttpServletRequest (com.sun.faces.mock.MockHttpServletRequest)2 MockHttpServletResponse (com.sun.faces.mock.MockHttpServletResponse)2 MockServletContext (com.sun.faces.mock.MockServletContext)2 Application (jakarta.faces.application.Application)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)1 HttpMethodRestrictionsPhaseListener (com.sun.faces.lifecycle.HttpMethodRestrictionsPhaseListener)1 MockExternalContext (com.sun.faces.mock.MockExternalContext)1