javax.faces.context.FacesContextFactory Java Examples

The following examples show how to use javax.faces.context.FacesContextFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestProject.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: ODAFacesContextFactory.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
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;
	}
}
 
Example #3
Source File: ContextUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: SignupServlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: ContextUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: SignupServlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: ODAFacesContextFactory.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public ODAFacesContextFactory(final FacesContextFactory delegate) {
	if (delegate instanceof FacesContextFactoryImpl) {
		_delegate = ((FacesContextFactoryImpl) delegate).getDelegate();
	} else {
		_delegate = delegate;
	}
}
 
Example #8
Source File: MockedJsf2TestContainer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #9
Source File: FacesContextServlet.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public void init(ServletConfig servletConfig) throws ServletException {
    this.servletConfig = servletConfig;
    // Create the FacesContextFactory
    this.contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
}
 
Example #10
Source File: DeltaSpikeFacesContextFactory.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
}
 
Example #11
Source File: DeltaSpikeFacesContextFactory.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FacesContextFactory getWrapped()
{
    return wrappedFacesContextFactory;
}