The following error message is shown when an action method of a <h:commandLink/>
JSF tag is called:
PWC3999: Cannot create a session after the response has been committed
The meaning of the error message is very straightforward, but my question is how the response could have been committed before the action method finishes execution.
(This error is only occurring time to time, not every time the commandLink is clicked.)
I use
JSF implementation: Mojarra V2.1.3
JSF component library: Primefaces V2.2.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)
EDIT : I attach some codes bellow, if this assist in getting the solution:
The markup:
<h:commandLink value="[Log in]"
action="#{headerAndFooterTemplateBacking.loginFilter}"
disabled="#{sessionScope.pk > 0 ? true : false}"
styleClass="#{sessionScope.pk > 0 ? 'disabled' : 'notDisabled'} padding" immediate="true"/>
The action method:
public void loginFilter() {
String from = FacesContext.getCurrentInstance().getViewRoot().getViewId();
int pk = getSessionMap().get("pk") == null ? -1 : (Integer) (getSessionMap().get("pk"));
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
Object selected = request.getParameter("selected");
if (pk <= 0) {
if (selected != null) {
getSessionMap().put("from", from + "?faces-redirect=true&selected=" + selected);
} else {
getSessionMap().put("from", from + "?faces-redirect=true");
}
getFacesContext().getApplication().getNavigationHandler().
handleNavigation(getFacesContext(), null,
"/pages/login/login.xhtml?faces-redirect=true");
}
}