Search in sources :

Example 1 with MyFacesContainerInitializer

use of org.apache.myfaces.webapp.MyFacesContainerInitializer in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFJsfServlet method doInit.

public void doInit(HttpServletRequest req, ServletConfig config) throws ServletException {
    try {
        CDI<Object> cdi = ContainerUtil.getContainer(NotesContext.getCurrent().getNotesDatabase());
        ServletContext context = config.getServletContext();
        // $NON-NLS-1$
        context.setAttribute("jakarta.enterprise.inject.spi.BeanManager", ContainerUtil.getBeanManager(cdi));
        // TODO investigate why partial state saving doesn't work with a basic form
        // $NON-NLS-1$ //$NON-NLS-2$
        context.setInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "false");
        Properties props = LibraryUtil.getXspProperties(module);
        // $NON-NLS-1$
        String projectStage = props.getProperty(ProjectStage.PROJECT_STAGE_PARAM_NAME, "");
        context.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage);
        Bundle b = FrameworkUtil.getBundle(FacesServlet.class);
        {
            ServletContainerInitializer initializer = new MyFacesContainerInitializer();
            Set<Class<?>> classes = null;
            HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class);
            if (types != null) {
                classes = buildMatchingClasses(types, b);
            }
            initializer.onStartup(classes, getServletContext());
        }
        {
            // Re-wrap the ServletContext to provide the context path
            javax.servlet.ServletContext oldCtx = ServletUtil.newToOld(getServletContext());
            ServletContext ctx = ServletUtil.oldToNew(req.getContextPath(), oldCtx, 5, 0);
            ctx.addListener(StartupServletContextListener.class);
            ServletUtil.getListeners(ctx, ServletContextListener.class).forEach(l -> l.contextInitialized(new ServletContextEvent(ctx)));
        }
        this.delegate = new FacesServlet();
        delegate.init(config);
    } catch (NotesAPIException e) {
        throw new ServletException(e);
    }
}
Also used : StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener) ProjectStage(jakarta.faces.application.ProjectStage) ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) CDI(jakarta.enterprise.inject.spi.CDI) XSPErrorPage(com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage) ServletConfig(jakarta.servlet.ServletConfig) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) URL(java.net.URL) FacesServlet(jakarta.faces.webapp.FacesServlet) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) FacesContext(jakarta.faces.context.FacesContext) ServletException(jakarta.servlet.ServletException) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) HttpSessionListener(jakarta.servlet.http.HttpSessionListener) HashSet(java.util.HashSet) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HttpSession(jakarta.servlet.http.HttpSession) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletUtil(org.openntf.xsp.jakartaee.servlet.ServletUtil) ModuleUtil(org.openntf.xsp.jakartaee.util.ModuleUtil) ServletRequestListener(jakarta.servlet.ServletRequestListener) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) LibraryUtil(org.openntf.xsp.jakartaee.util.LibraryUtil) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) PrintWriter(java.io.PrintWriter) Properties(java.util.Properties) AbstractProxyingContext(org.openntf.xsp.cdi.context.AbstractProxyingContext) Set(java.util.Set) IOException(java.io.IOException) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) HttpServlet(jakarta.servlet.http.HttpServlet) List(java.util.List) HttpSessionEvent(jakarta.servlet.http.HttpSessionEvent) StringUtil(com.ibm.commons.util.StringUtil) ServletContextEvent(jakarta.servlet.ServletContextEvent) Annotation(java.lang.annotation.Annotation) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) DiscoveryUtil(org.openntf.xsp.cdi.util.DiscoveryUtil) ServletContext(jakarta.servlet.ServletContext) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AccessController(java.security.AccessController) ServletRequestEvent(jakarta.servlet.ServletRequestEvent) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) ContainerUtil(org.openntf.xsp.cdi.util.ContainerUtil) ServletContextListener(jakarta.servlet.ServletContextListener) HashSet(java.util.HashSet) Set(java.util.Set) Bundle(org.osgi.framework.Bundle) FacesServlet(jakarta.faces.webapp.FacesServlet) Properties(java.util.Properties) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) ServletException(jakarta.servlet.ServletException) ServletContext(jakarta.servlet.ServletContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) ServletContextEvent(jakarta.servlet.ServletContextEvent) StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener)

Aggregations

StringUtil (com.ibm.commons.util.StringUtil)1 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 ComponentModule (com.ibm.designer.runtime.domino.adapter.ComponentModule)1 XSPErrorPage (com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage)1 NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)1 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 CDI (jakarta.enterprise.inject.spi.CDI)1 ProjectStage (jakarta.faces.application.ProjectStage)1 FacesContext (jakarta.faces.context.FacesContext)1 FacesServlet (jakarta.faces.webapp.FacesServlet)1 ServletConfig (jakarta.servlet.ServletConfig)1 ServletContainerInitializer (jakarta.servlet.ServletContainerInitializer)1 ServletContext (jakarta.servlet.ServletContext)1 ServletContextEvent (jakarta.servlet.ServletContextEvent)1 ServletContextListener (jakarta.servlet.ServletContextListener)1 ServletException (jakarta.servlet.ServletException)1 ServletRequestEvent (jakarta.servlet.ServletRequestEvent)1 ServletRequestListener (jakarta.servlet.ServletRequestListener)1 HandlesTypes (jakarta.servlet.annotation.HandlesTypes)1 HttpServlet (jakarta.servlet.http.HttpServlet)1