如何检测是否调用了以前的重定向? [英] How to detect if a previous redirect was invoked?

查看:190
本文介绍了如何检测是否调用了以前的重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证支持bean中 preRenderView 事件中的视图参数我发现每个事件< f:event> :

Validating view-parameters in preRenderView event in the backing bean I observed that each event <f:event> is still fired even if any of the methods invoked a redirect using:

FacesContext.getExternalContext()。redirect(url);

如果在多个事件中调用重定向,将引发非法状态错误异常。

If in multiple events a redirect is invoked an illegal state error exception will be thrown.

为了防止这种情况,我想知道是否以及如何通常检测到已经调用了重定向,并处理第一次或最后一次重定向。

To prevent this I would like to know if and how it is possible to generally detect wether a redirect was already invoked and either process the first or the last redirect.

推荐答案

您可以使用 FacesContext#getRenderResponse()来确认流程(或订购)继续进行 RENDER_RESPONSE 阶段。这将检查组件是否已调用 renderResponse()方法,指示运行时将控制转移到 RENDER_RESPONSE 阶段。通常,此时尝试对响应流执行任何操作都是不安全的。

You can use the FacesContext#getRenderResponse() to confirm if the process (or order) to proceed to the RENDER_RESPONSE phase has been initiated. This checks whether renderResponse() method has been called by a component, signalling the runtime to transfer control to the RENDER_RESPONSE phase. Generally at this point it's unsafe to attempt to do anything with the response stream.

RENDER_RESPONSE 阶段的另一条路线是 FacesContext #responseComplete()方法。然而,这并不直接触发响应处理。相反,它是向运行时指示已到达 RENDER_RESPONSE 的最终标志。

Another route to the RENDER_RESPONSE phase is the FacesContext#responseComplete() method. This however, does not directly trigger the response processing. Rather, it's the final flag to indicate to the runtime that RENDER_RESPONSE has been arrived at.

所以,按照spec, FacesContext #getResponseComplete()是验证响应状态的最终检查

So, per the spec, FacesContext#getResponseComplete() is the ultimate check to verify the state of the response


在某些情况下,可能已为请求调用了renderResponse()和responseComplete()。在这种情况下,JSF实现必须遵循
responseComplete()调用(如果已经建立),然后再检查是否调用了renderResponse()。

In some circumstances, it is possible that both renderResponse()and responseComplete()might have been called for the request. In this case, the JSF implementation must respect the responseComplete()call (if it was made) before checking to see if renderResponse()was called.

这篇关于如何检测是否调用了以前的重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆