当前位置: 首页>>代码示例>>Java>>正文


Java FacesContextFactory.getFacesContext方法代码示例

本文整理汇总了Java中javax.faces.context.FacesContextFactory.getFacesContext方法的典型用法代码示例。如果您正苦于以下问题:Java FacesContextFactory.getFacesContext方法的具体用法?Java FacesContextFactory.getFacesContext怎么用?Java FacesContextFactory.getFacesContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.faces.context.FacesContextFactory的用法示例。


在下文中一共展示了FacesContextFactory.getFacesContext方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:PrettyUrlFilter.java

示例2: getFacesContextImpl

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:34,代码来源:FacesHelper.java

示例3: createFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
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;
}
 
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:20,代码来源:TestProject.java

示例4: getFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:mattiamascia,项目名称:atask,代码行数:30,代码来源:DownloadCtr.java

示例5: getFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
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;
}
 
开发者ID:wangyeee,项目名称:IBE-Secure-Message,代码行数:17,代码来源:SessionFilter.java

示例6: getFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
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;
}
 
开发者ID:play4science,项目名称:gwap,代码行数:27,代码来源:FacesContextBuilder.java

示例7: doFilter

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:41,代码来源:FacesExtensionFilter.java

示例8: lookupBeanFromExternalServlet

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:44,代码来源:ContextUtil.java

示例9: lookupBeanFromExternalServlet

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:40,代码来源:SignupServlet.java

示例10: FacesContextBroker

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:16,代码来源:FacesContextBroker.java

示例11: initFacesContext

import javax.faces.context.FacesContextFactory; //导入方法依赖的package包/类
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));
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:16,代码来源:MockedJsf2TestContainer.java


注:本文中的javax.faces.context.FacesContextFactory.getFacesContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。