本文介绍了如何知道我是否在发回邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在JSF文档中阅读了 具有 isPostBack() 方法.我如何(和在哪里)拥有ResponseStateManager的实例?

I've read in JSF docs that ResponseStateManager has a isPostBack() method. How (and where) can I have an instance of ResponseStateManager?

推荐答案

取决于JSF版本.

在JSF 1.0/1.1中,没有 ResponseStateManager#isPostback() 方法可用.检查javax.faces.ViewState参数是否在请求参数映射中存在,如 ExternalContext#getRequestParameterMap() .

In JSF 1.0/1.1, there's no ResponseStateManager#isPostback() method available. check if javax.faces.ViewState parameter is present in the request parameter map as available by ExternalContext#getRequestParameterMap().

public static boolean isPostback() {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    return externalContext.getRequestParameterMap().contains("javax.faces.ViewState");
}

在JSF 1.2中,确实使用了ResponseStateManager#isPostback(),它实际上检查了请求参数映射中javax.faces.ViewState参数的存在.

In JSF 1.2, indeed use ResponseStateManager#isPostback() which in turn actually checks the presence of javax.faces.ViewState parameter in the request parameter map.

public static boolean isPostback() {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getRenderKit().getResponseStateManager().isPostback(context);
}

在JSF 2.0中,请改用 FacesContext#isPostback() ,实际上它实际上是委派给ResponseStateManager#isPostback().

In JSF 2.0, instead use FacesContext#isPostback(), which under the covers actually delegates to ResponseStateManager#isPostback().

public static boolean isPostback() {
    return FacesContext.getCurrentInstance().isPostback();
}

这篇关于如何知道我是否在发回邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:15