Re: Exception occured “java.lang.IllegalStateException: Context is already active”

Splash Forums PrettyFaces Users Exception occured "java.lang.IllegalStateException: Context is already active" Re: Exception occured “java.lang.IllegalStateException: Context is already active”


Hey there! I tested Mojarra 2.1.2 on Tomcat 7 and everything works fine.

I also had a quick look at the Mojarra source. They are doing the following in ExternalContextImpl:

public void responseFlushBuffer() throws IOException {
getELFlash().doLastPhaseActions(FacesContext.getCurrentInstance(), false);

And in ELFlash:

public void doLastPhaseActions(FacesContext context, boolean outgoingResponseIsRedirect) {
ExternalContext extContext = context.getExternalContext();

The access to context in doLastPhaseActions() seems to cause the NPE. This means that FacesContext.getCurrentInstance() returns null in ExternalContextImpl.

Could you perhaps test the following: Add an URL action to your mapping like this:

<url-mapping id="viewCategory">
<pattern value="/electAdmin" />
<action>#{testBean.testMethod}</action> <!-- LOOK HERE --->
<query-param name="testid"> #{candidate_handler.testid} </query-param>


public class TestBean {

public void testMethod() {
System.out.println("FacesContext ----> "+FacesContext.getCurrentInstance());


I would be interested to see if the FacesContext is null even before RENDER_RESPONSE phase. I really think this is a Mojarra bug. I don’t think it is allowed that FacesContext.getCurrentInstance() returns null during RENDER_RESPONSE!