I've read in JSF docs that ResponseStateManager
has a isPostBack()
method. How (and where) can I have an instance of ResponseStateManager
?
我在JSF文档中读到ResponseStateManager有一个isPostBack()方法。我如何(以及在哪里)拥有ResponseStateManager的实例?
3 个解决方案
#1
How to know if I am in a postback?
如何知道我是否在回发?
Depends on JSF version.
取决于JSF版本。
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()
.
在JSF 1.0 / 1.1中,没有可用的ResponseStateManager#isPostback()方法。检查请求参数映射中是否存在javax.faces.ViewState参数,该参数由ExternalContext#getRequestParameterMap()提供。
public static boolean isPostback() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
return externalContext.getRequestParameterMap().contains("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.
在JSF 1.2中,确实使用ResponseStateManager#isPostback(),它实际上检查请求参数映射中是否存在javax.faces.ViewState参数。
public static boolean isPostback() {
FacesContext context = FacesContext.getCurrentInstance();
return context.getRenderKit().getResponseStateManager().isPostback(context);
}
In JSF 2.0, instead use FacesContext#isPostback()
, which under the covers actually delegates to ResponseStateManager#isPostback()
.
在JSF 2.0中,使用FacesContext#isPostback(),它实际上委托给ResponseStateManager#isPostback()。
public static boolean isPostback() {
return FacesContext.getCurrentInstance().isPostback();
}
#2
Indeed, before jsf1.2, isPostBack was obtained through the requestScope of the current instance of FaceContext.
实际上,在jsf1.2之前,isPostBack是通过当前FaceContext实例的requestScope获得的。
Since JSF1.2, The ResponseStateManager (helper class to StateManager that knows the specific rendering technology being used to generate the response, a singleton abstract class, vended by the RenderKit.)
从JSF1.2开始,ResponseStateManager(StateManager的助手类,知道用于生成响应的特定渲染技术,一个单独的抽象类,由RenderKit出售。)
During the restore view phase of the life cycle, ViewHandler retrieves the ResponseStateManager object in order to test if the request is a postback or an initial request.
在生命周期的恢复视图阶段,ViewHandler检索ResponseStateManager对象,以测试请求是回发还是初始请求。
If a request is a postback, therestoreView method of ViewHandler is called. This method uses theResponseStateManager object to re-build the component tree and restore state. After the tree is built and state is restored, theViewHandler instance is not needed until the render response phase occurs again.
如果请求是回发,则调用ViewHandler的therestoreView方法。此方法使用ResponseStateManager对象重新构建组件树并恢复状态。构建树并恢复状态后,在再次发生渲染响应阶段之前不需要ViewHandler实例。
That article mentionned above (Creating and Using a Custom Render Kit) illustrates how to implement/get an ResponseStateManager, through a RenderKit (defined by the tag handler implementing the tag that renders the component).
May be this is enough for you to get your own ResponseStateManager in your context ?
上面提到的那篇文章(创建和使用自定义渲染工具包)说明了如何通过RenderKit实现/获取ResponseStateManager(由实现呈现组件的标记的标记处理程序定义)。这可能足以让您在上下文中获得自己的ResponseStateManager吗?
#3
For JSF1.2
public static boolean isPostback(){
FacesContext context = FacesContext.getCurrentInstance();
return context != null && context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
}
#1
How to know if I am in a postback?
如何知道我是否在回发?
Depends on JSF version.
取决于JSF版本。
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()
.
在JSF 1.0 / 1.1中,没有可用的ResponseStateManager#isPostback()方法。检查请求参数映射中是否存在javax.faces.ViewState参数,该参数由ExternalContext#getRequestParameterMap()提供。
public static boolean isPostback() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
return externalContext.getRequestParameterMap().contains("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.
在JSF 1.2中,确实使用ResponseStateManager#isPostback(),它实际上检查请求参数映射中是否存在javax.faces.ViewState参数。
public static boolean isPostback() {
FacesContext context = FacesContext.getCurrentInstance();
return context.getRenderKit().getResponseStateManager().isPostback(context);
}
In JSF 2.0, instead use FacesContext#isPostback()
, which under the covers actually delegates to ResponseStateManager#isPostback()
.
在JSF 2.0中,使用FacesContext#isPostback(),它实际上委托给ResponseStateManager#isPostback()。
public static boolean isPostback() {
return FacesContext.getCurrentInstance().isPostback();
}
#2
Indeed, before jsf1.2, isPostBack was obtained through the requestScope of the current instance of FaceContext.
实际上,在jsf1.2之前,isPostBack是通过当前FaceContext实例的requestScope获得的。
Since JSF1.2, The ResponseStateManager (helper class to StateManager that knows the specific rendering technology being used to generate the response, a singleton abstract class, vended by the RenderKit.)
从JSF1.2开始,ResponseStateManager(StateManager的助手类,知道用于生成响应的特定渲染技术,一个单独的抽象类,由RenderKit出售。)
During the restore view phase of the life cycle, ViewHandler retrieves the ResponseStateManager object in order to test if the request is a postback or an initial request.
在生命周期的恢复视图阶段,ViewHandler检索ResponseStateManager对象,以测试请求是回发还是初始请求。
If a request is a postback, therestoreView method of ViewHandler is called. This method uses theResponseStateManager object to re-build the component tree and restore state. After the tree is built and state is restored, theViewHandler instance is not needed until the render response phase occurs again.
如果请求是回发,则调用ViewHandler的therestoreView方法。此方法使用ResponseStateManager对象重新构建组件树并恢复状态。构建树并恢复状态后,在再次发生渲染响应阶段之前不需要ViewHandler实例。
That article mentionned above (Creating and Using a Custom Render Kit) illustrates how to implement/get an ResponseStateManager, through a RenderKit (defined by the tag handler implementing the tag that renders the component).
May be this is enough for you to get your own ResponseStateManager in your context ?
上面提到的那篇文章(创建和使用自定义渲染工具包)说明了如何通过RenderKit实现/获取ResponseStateManager(由实现呈现组件的标记的标记处理程序定义)。这可能足以让您在上下文中获得自己的ResponseStateManager吗?
#3
For JSF1.2
public static boolean isPostback(){
FacesContext context = FacesContext.getCurrentInstance();
return context != null && context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
}