/** * @param request * @param response * @return */ private FacesContext getFacesContext(final ServletRequest request, final ServletResponse response) { FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext != null) { return facesContext; } FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder .getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); ServletContext servletContext = ((HttpServletRequest) request).getSession().getServletContext(); facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle); return facesContext; }
/** * 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; }
public StarterFacesContextFactory() { if (_debug) System.out.println(getClass().getName() + " created"); Object inst; try { @SuppressWarnings("rawtypes") Class delegateClass = DominoFacesContextFactoryImpl.class; inst = delegateClass.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new FacesExceptionEx(e); } if (inst instanceof FacesContextFactory) { _delegate = (FacesContextFactory) inst; } else { _delegate = null; } }
public static FacesContext createFacesContext(AbstractXspTest test, HttpServletRequest request) throws Exception { FacesController controller = (FacesController) test.getTestLocalVars().get("controller"); if( null == controller ){ bootstrap(test); controller = (FacesController) test.getTestLocalVars().get("controller"); } LocalServletContext servletContext = (LocalServletContext) test.getTestLocalVars().get("servletContext"); HttpServletResponse response = new LocalHttpServletResponse(servletContext, null); FacesContextFactory factory1 = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); FacesContext context = factory1.getFacesContext(servletContext, request, response, controller.getLifecycle()); String sessionId = request.getSession().getId(); SessionUtil.setSessionId(context, sessionId); test.getTestLocalVars().put("facesContext", context); return context; }
public OpenNTFFacesContextFactory() { if (_debug) System.out.println(getClass().getName() + " created"); Object inst; try { @SuppressWarnings("rawtypes") Class delegateClass = DominoFacesContextFactoryImpl.class; inst = delegateClass.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new FacesExceptionEx(e); } if (inst instanceof FacesContextFactory) { _delegate = (FacesContextFactory) inst; } else { _delegate = null; } }
/** * Gets the faces context. * * @param request the request * @param response the response * @return the faces context */ protected FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) { FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext == null) { FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder .getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); facesContext = contextFactory.getFacesContext(request.getSession() .getServletContext(), request, response, lifecycle); // set a new viewRoot, otherwise context.getViewRoot returns null UIViewRoot view = facesContext.getApplication().getViewHandler() .createView(facesContext, ""); facesContext.setViewRoot(view); } return facesContext; }
public FacesContext getFacesContext(ServletRequest request, ServletResponse response) { FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext != null) { return facesContext; } FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); ServletContext servletContext = ((HttpServletRequest) request).getSession().getServletContext(); facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle); InnerFacesContext.setFacesContextAsCurrentInstance(facesContext); if (null == facesContext.getViewRoot()) { facesContext.setViewRoot(new UIViewRoot()); } return facesContext; }
/** * Constructor */ public OpenntfFacesContextFactory() { // System.out.println("Creating new OpenntfFacesContextFactory"); Object inst; try { @SuppressWarnings("rawtypes") Class delegateClass = DominoFacesContextFactoryImpl.class; inst = delegateClass.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new FacesExceptionEx(e); } if (inst instanceof FacesContextFactory) { _delegate = (FacesContextFactory) inst; } else { System.out.println("WARNING: Delegate for OpenntfFacesContextFactory is null. Many things will probably break."); _delegate = null; } }
public ODAFacesContextFactory() { Object inst; try { @SuppressWarnings("rawtypes") Class delegateClass = DominoFacesContextFactoryImpl.class; inst = delegateClass.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new FacesExceptionEx(e); } if (inst instanceof FacesContextFactory) { _delegate = (FacesContextFactory) inst; } else { _delegate = null; } }
public FacesContext getFacesContext(final ServletRequest request, final ServletResponse response, HttpSession ses) { FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext != null) { return facesContext; } FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder .getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); ServletContext servletContext = ses.getServletContext(); facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle); InnerFacesContext.setFacesContextAsCurrentInstance(facesContext); if (null == facesContext.getViewRoot()) { UIViewRoot u = new UIViewRoot(); u.setViewId("irgendwas"); facesContext.setViewRoot(u); } return facesContext; }
/** * Override of Servlet.init(); */ @Override public void init( ServletConfig config ) throws ServletException { super.init(config); // Acquire our FacesContextFactory instance try { _facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory (FactoryFinder.FACES_CONTEXT_FACTORY); } catch (FacesException e) { Throwable rootCause = e.getCause(); if (rootCause == null) { throw e; } else { throw new ServletException(e.getMessage(), rootCause); } } // Acquire our Lifecycle instance _lifecycle = new _ResourceLifecycle(); _initDebug(config); _loaders = new ConcurrentHashMap<String, ResourceLoader>(); _loaderErrors = new ConcurrentHashMap<String, Class<?>>(); }
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); } } }
/** * Helper method to look up backing bean, when OUTSIDE faces in a servlet. * Don't forget to cast! * e.g. (TemplateBean) ContextUtil.lookupBean("template") * * @param beanName * @param request servlet request * @param response servlet response * @return the backing bean */ public static Serializable lookupBeanFromExternalServlet(String beanName, HttpServletRequest request, HttpServletResponse response) { // prepare lifecycle LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); // in the integrated environment, we can't get the ServletContext from the // HttpSession of the request - because the HttpSession is webcontainer-wide, // its not tied to a particular servlet. ServletContext servletContext = M_servletContext; if (servletContext == null) { servletContext = request.getSession().getServletContext(); } FacesContext facesContext = fcFactory.getFacesContext(servletContext, request, response, lifecycle); ApplicationFactory factory = (ApplicationFactory) FactoryFinder. getFactory( FactoryFinder.APPLICATION_FACTORY); Application application = factory.getApplication(); Serializable bean = (Serializable) application.getVariableResolver().resolveVariable( facesContext, beanName); return bean; }
/** * Helper method to look up backing bean, when OUTSIDE faces in a servlet. * Don't forget to cast! e.g. (TemplateBean) * ContextUtil.lookupBean("template") * * @param beanName * @param request * servlet request * @param response * servlet response * @return the backing bean */ public Serializable lookupBeanFromExternalServlet(String beanName, HttpServletRequest request, HttpServletResponse response) { // prepare lifecycle LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); // in the integrated environment, we can't get the ServletContext from // the // HttpSession of the request - because the HttpSession is // webcontainer-wide, // its not tied to a particular servlet. if (this.servletContext == null) { servletContext = request.getSession().getServletContext(); } FacesContext facesContext = fcFactory.getFacesContext(servletContext, request, response, lifecycle); ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); Application application = factory.getApplication(); Serializable bean = (Serializable) application.getVariableResolver().resolveVariable(facesContext, beanName); return bean; }
public StarterFacesContextFactory(FacesContextFactory delegate) { if (_debug) System.out.println(getClass().getName() + " created from delegate"); if (delegate instanceof FacesContextFactoryImpl) { _delegate = ((FacesContextFactoryImpl) delegate).getDelegate(); } else { _delegate = delegate; } }
/** * Constructs a Faces context broker from the current HTTP request. * @param request the HTTP request * @param response the HTTP response */ public FacesContextBroker(HttpServletRequest request, HttpServletResponse response) { FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); ServletContext servletContext = ((HttpServletRequest)request).getSession().getServletContext(); FacesContext fc = contextFactory.getFacesContext(servletContext, request, response, lifecycle); InnerFacesContext.setFacesContextAsCurrentInstance(fc); UIViewRoot view = fc.getApplication().getViewHandler().createView(fc,"/gptInnerFacesContext"); fc.setViewRoot(view); }
public OpenNTFFacesContextFactory(FacesContextFactory delegate) { if (_debug) System.out.println(getClass().getName() + " created from delegate"); if (delegate instanceof FacesContextFactoryImpl) { _delegate = ((FacesContextFactoryImpl) delegate).getDelegate(); } else { _delegate = delegate; } }
/** * Overloaded constructor * * @param delegate * FacesContextFactory, delegate of OpenntfFacesContextFactory */ public OpenntfFacesContextFactory(final FacesContextFactory delegate) { // System.out.println("Creating new OpenntfFacesContextFactory from delegate"); if (delegate instanceof FacesContextFactoryImpl) { _delegate = ((FacesContextFactoryImpl) delegate).getDelegate(); } else { _delegate = delegate; } }
public ODAFacesContextFactory(final FacesContextFactory delegate) { if (delegate instanceof FacesContextFactoryImpl) { _delegate = ((FacesContextFactoryImpl) delegate).getDelegate(); } else { _delegate = delegate; } }
protected void initFacesContext() { FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); this.facesContext = facesContextFactory.getFacesContext( this.servletContext, this.request, this.response, this.lifecycle); ((MockFacesContext) this.facesContext).setApplication(this.application); ExceptionHandler exceptionHandler = ((ExceptionHandlerFactory) FactoryFinder.getFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY)).getExceptionHandler(); this.facesContext.setExceptionHandler(exceptionHandler); ((MockFacesContext) this.facesContext).setExternalContext( new MockExternalContext(this.servletContext, this.request, this.response)); }
public FacesContextFactoryImpl(FacesContextFactory factory) { _factory = factory; }
@Override public FacesContextFactory getWrapped() { return _factory; }
public void init(ServletConfig servletConfig) throws ServletException { this.servletConfig = servletConfig; // Create the FacesContextFactory this.contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); }
@Override public void init(ServletConfig config) throws ServletException { m_Config = config; m_ContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); }
/** * Constructor for wrapping the given {@link FacesContextFactory} * * @param wrappedFacesContextFactory wrapped faces-context-factory which should be used */ public DeltaSpikeFacesContextFactory(FacesContextFactory wrappedFacesContextFactory) { this.wrappedFacesContextFactory = wrappedFacesContextFactory; this.deactivated = !ClassDeactivationUtils.isActivated(getClass()); }
/** * {@inheritDoc} */ @Override public FacesContextFactory getWrapped() { return wrappedFacesContextFactory; }