use of javax.faces.lifecycle.LifecycleFactory in project Payara by payara.
the class JSFTestServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
ServletContext context = getServletContext();
FacesContext facesContext = facesContextFactory.getFacesContext(context, request, response, lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE));
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(facesContext, null);
facesContext.setViewRoot(viewRoot);
PrintWriter pw = response.getWriter();
pw.println("Created viewRoot " + viewRoot);
pw.flush();
pw.close();
}
use of javax.faces.lifecycle.LifecycleFactory in project deltaspike by apache.
the class MockedJsf2TestContainer method initLifecycle.
protected void initLifecycle() {
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
this.lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
}
use of javax.faces.lifecycle.LifecycleFactory in project acs-community-packaging by Alfresco.
the class FacesHelper method getFacesContextImpl.
/**
* 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;
}
use of javax.faces.lifecycle.LifecycleFactory in project ma-core-public by infiniteautomation.
the class FacesExtensionFilter method doFilter.
/* (non-Javadoc)
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
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);
}
}
}
Aggregations