Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's not possible using the standard servlet API, so you really need to either manually create the <code>FacesContext</code>, or if it's a 3rd party URL-rewriting framework, check its documentation if they don't already provide any API for the purpose.</p> <p>You could manually create the <code>FacesContext</code> based on <code>request</code> and <code>response</code> as follows:</p> <pre><code>public static FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) { FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext == null) { LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(request.getServletContext(), request, response, lifecycle); facesContext.setViewRoot(facesContext.getApplication().getViewHandler().createView(facesContext, "")); FacesContextWrapper.setCurrentInstance(facesContext); } return facesContext; } private static abstract class FacesContextWrapper extends FacesContext { protected static void setCurrentInstance(FacesContext facesContext) { FacesContext.setCurrentInstance(facesContext); } } </code></pre> <p>Please note that this isn't considered "best practice". If there's a way without manually creating the <code>FacesContext</code>, by all means use it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload