<h:commandLink/>
调用 JSF 标记的操作方法时显示以下错误消息:
PWC3999: Cannot create a session after the response has been committed
错误消息的含义非常简单,但我的问题是如何在操作方法完成执行之前提交响应。
(此错误只是不时发生,而不是每次单击 commandLink 时。)
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)
编辑:我在下面附上一些代码,如果这有助于获得解决方案:
标记:
<h:commandLink value="[Log in]"
action="#{headerAndFooterTemplateBacking.loginFilter}"
disabled="#{sessionScope.pk > 0 ? true : false}"
styleClass="#{sessionScope.pk > 0 ? 'disabled' : 'notDisabled'} padding" immediate="true"/>
动作方法:
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");
}
}