Search in sources :

Example 1 with Lifecycle

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

the class CdiLifecycleFactory method getLifecycleIds.

@Override
public Iterator<String> getLifecycleIds() {
    ArrayList<String> lifecycleIds = new ArrayList<>();
    getWrapped().getLifecycleIds().forEachRemaining(lifecycleIds::add);
    BeanManager beanManager = getBeanManager();
    AnnotatedType<Lifecycle> type = beanManager.createAnnotatedType(Lifecycle.class);
    Set<Bean<?>> beans = beanManager.getBeans(type.getBaseType());
    Iterator<Bean<?>> iterator = beans.iterator();
    while (iterator.hasNext()) {
        Bean<?> bean = iterator.next();
        if (bean.getBeanClass().isAnnotationPresent(Named.class)) {
            Named named = bean.getBeanClass().getAnnotation(Named.class);
            lifecycleIds.add(named.value());
        }
    }
    return lifecycleIds.iterator();
}
Also used : Named(jakarta.inject.Named) Lifecycle(jakarta.faces.lifecycle.Lifecycle) ArrayList(java.util.ArrayList) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Bean(jakarta.enterprise.inject.spi.Bean)

Example 2 with Lifecycle

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

the class LifecycleConfigProcessor method addPhaseListeners.

// --------------------------------------------------------- Private Methods
private void addPhaseListeners(ServletContext sc, FacesContext facesContext, LifecycleFactory factory, NodeList phaseListeners) {
    if (phaseListeners != null && phaseListeners.getLength() > 0) {
        for (int i = 0, size = phaseListeners.getLength(); i < size; i++) {
            Node phaseListenerNode = phaseListeners.item(i);
            String phaseListenerClassName = getNodeText(phaseListenerNode);
            if (phaseListenerClassName != null) {
                boolean[] didPerformInjection = { false };
                PhaseListener phaseListener = (PhaseListener) createInstance(sc, facesContext, phaseListenerClassName, PhaseListener.class, null, phaseListenerNode, true, didPerformInjection);
                if (phaseListener != null) {
                    if (didPerformInjection[0]) {
                        appPhaseListeners.add(phaseListener);
                    }
                    for (Iterator<String> t = factory.getLifecycleIds(); t.hasNext(); ) {
                        String lfId = t.next();
                        Lifecycle lifecycle = factory.getLifecycle(lfId);
                        if (LOGGER.isLoggable(FINE)) {
                            LOGGER.log(FINE, format("Adding PhaseListener ''{0}'' to lifecycle ''{0}}", phaseListenerClassName, lfId));
                        }
                        lifecycle.addPhaseListener(phaseListener);
                    }
                }
            }
        }
    }
}
Also used : PhaseListener(jakarta.faces.event.PhaseListener) Node(org.w3c.dom.Node) Lifecycle(jakarta.faces.lifecycle.Lifecycle)

Example 3 with Lifecycle

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

the class WebConfiguration method doPostBringupActions.

public void doPostBringupActions() {
    if (deferredLoggingActions != null) {
        for (DeferredLoggingAction loggingAction : deferredLoggingActions) {
            loggingAction.log();
        }
    }
    // Add the HttpMethodRestrictionPhaseListener if the parameter is enabled.
    boolean enabled = isOptionEnabled(BooleanWebContextInitParameter.EnableHttpMethodRestrictionPhaseListener);
    if (enabled) {
        LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
        PhaseListener listener = null;
        for (String lifecycleId : toIterable(factory.getLifecycleIds())) {
            Lifecycle lifecycle = factory.getLifecycle(lifecycleId);
            boolean foundExistingListenerInstance = false;
            for (PhaseListener curListener : lifecycle.getPhaseListeners()) {
                if (curListener instanceof HttpMethodRestrictionsPhaseListener) {
                    foundExistingListenerInstance = true;
                    break;
                }
            }
            if (!foundExistingListenerInstance) {
                if (listener == null) {
                    listener = new HttpMethodRestrictionsPhaseListener();
                }
                lifecycle.addPhaseListener(listener);
            }
        }
    }
    discoverResourceLibraryContracts();
}
Also used : PhaseListener(jakarta.faces.event.PhaseListener) HttpMethodRestrictionsPhaseListener(com.sun.faces.lifecycle.HttpMethodRestrictionsPhaseListener) LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) Lifecycle(jakarta.faces.lifecycle.Lifecycle) HttpMethodRestrictionsPhaseListener(com.sun.faces.lifecycle.HttpMethodRestrictionsPhaseListener)

Example 4 with Lifecycle

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

the class LifecycleFactoryImpl method getLifecycle.

@Override
public Lifecycle getLifecycle(String lifecycleId) throws FacesException {
    if (lifecycleId == null) {
        throw new NullPointerException(MessageUtils.getExceptionMessageString(NULL_PARAMETERS_ERROR_MESSAGE_ID, "lifecycleId"));
    }
    if (lifecycleMap.get(lifecycleId) == null) {
        Object[] params = { lifecycleId };
        String message = MessageUtils.getExceptionMessageString(CANT_CREATE_LIFECYCLE_ERROR_MESSAGE_ID, params);
        throw new IllegalArgumentException(message);
    }
    Lifecycle result = lifecycleMap.get(lifecycleId);
    if (LOGGER.isLoggable(FINE)) {
        LOGGER.fine("getLifecycle: " + lifecycleId + " " + result);
    }
    return result;
}
Also used : Lifecycle(jakarta.faces.lifecycle.Lifecycle)

Example 5 with Lifecycle

use of jakarta.faces.lifecycle.Lifecycle in project faces by jakartaee.

the class TestServlet method initFacesContext.

private FacesContext initFacesContext(HttpServletRequest request, HttpServletResponse response) {
    LifecycleFactory lifeFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifeFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    FacesContextFactory facesFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    return facesFactory.getFacesContext(servletContext, request, response, lifecycle);
}
Also used : LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) Lifecycle(jakarta.faces.lifecycle.Lifecycle) FacesContextFactory(jakarta.faces.context.FacesContextFactory)

Aggregations

Lifecycle (jakarta.faces.lifecycle.Lifecycle)25 PrintWriter (java.io.PrintWriter)13 LifecycleFactory (jakarta.faces.lifecycle.LifecycleFactory)12 PhaseListener (jakarta.faces.event.PhaseListener)6 FacesContextFactory (jakarta.faces.context.FacesContextFactory)4 ServletException (jakarta.servlet.ServletException)4 IOException (java.io.IOException)4 FacesContext (jakarta.faces.context.FacesContext)3 ArrayList (java.util.ArrayList)3 Bean (jakarta.enterprise.inject.spi.Bean)2 BeanManager (jakarta.enterprise.inject.spi.BeanManager)2 Application (jakarta.faces.application.Application)2 Named (jakarta.inject.Named)2 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)1 HttpMethodRestrictionsPhaseListener (com.sun.faces.lifecycle.HttpMethodRestrictionsPhaseListener)1 MockHttpServletRequest (com.sun.faces.mock.MockHttpServletRequest)1 MockHttpServletResponse (com.sun.faces.mock.MockHttpServletResponse)1 MockServletContext (com.sun.faces.mock.MockServletContext)1 FacesException (jakarta.faces.FacesException)1 ApplicationFactory (jakarta.faces.application.ApplicationFactory)1