Opening the JSF page gives me the following exception:
Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been
It was happening to me too.
I used to have Mojarra 2.1.13 and after updating it to 2.1.29 the problem solved itself, without any changes in my code.
The reason is that:
HttpSession
So the solution is to create the session before the Facelet (/JSP) page is printed. An crude example could be like:
@PostConstruct
void initialiseSession() {
FacesContext.getCurrentInstance().getExternalContext().getSession(true);
}
/napu
I put this in my web.xml to solve the problem for one of my apps.
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
What is weird though is that I have several other applications hosted on this same glass fish instance that doesn't require this voodoo in the web.xml.
I strongly want to believe this is not the solution, cos it doesn't make any sense to me why this particular app requires it and the others didn't. But for now it works.
[SOLVED]
It took days to diagnose this problem, but finally I am able to solve this problem.
It was actually @ViewScoped
and it has a managed property DAO object which was not serialized. So after view is rendered, facelets also produce this exception, but JSF view already rendered and that's why this exception showed.
Solution: Make all objects serialized in @ViewScoped
bean, and mark "transient" who are not serialized like in my case it was DAO object in JSF @ViewScoped
.