On Wed, Oct 19, 2011 at 11:07 AM, Ed Burns <edward.burns_at_oracle.com> wrote:
>>>>>> On Fri, 14 Oct 2011 21:38:20 +0000 (GMT), <gudnabrsam_at_gmail.com> said:
>
> MB> Would it not be better to revise the behavior of the various
> MB> cooperating components such that the redirect is performed *after* the
> MB> current phase has completed, making up simply an alternative path in
> MB> the implementation of RENDER_RESPONSE? If not, why not? As yet the
> MB> most straightforward workaround I have come up with is an
> MB> ExternalContextWrapper that intercepts the #redirect() call to do the
> MB> necessary cleanup.
>
> The current specification and implementation of
> ExternalContext.redirect() means "redirect NOW". I don't want to change
> that since it seems likely some applications are depending on the
> immediate nature of calling redirect(). However, you do have a good
> point: the afterPhase() listeners are not being invoked early enough to
> take action based on the redirect().
>
> What would you think if we made it so redirect() retains its immediacy,
> but we move up the invocation of the afterPhase() listeners so they
> happen before the redirect() actually occurs?
>
Hi, Ed; thanks for your attention to this. I mentioned to you on IRC
that I have some add-on code that implements my recommendation. In a
nutshell, this code:
* provides a custom ExternalContext, overriding redirect() to save
the requested redirect URL to the requestMap, calling renderResponse()
against the current FacesContext
* provides a custom Lifecycle, overriding render() such to execute
any redirect deferred by the custom ExternalContext rather than
calling through to the wrapped Lifecycle's render() implementation
These have the effect of allowing afterPhase() to be triggered while
the request is active. Additionally, I have created a custom
FacesContext that returns false from getResponseComplete() while a
redirect is pending. Having called renderResponse() from the custom
ExternalContext when the redirect is requested, I personally can't
think of anything else that will happen beyond following up the
afterPhase listeners properly, so this seems equivalent to your
suggestion to move up the invocation of the afterPhase() listeners.
RENDER_RESPONSE afterPhase() would still be called after the response
is completed, but this is IMO as it should be and should be the status
quo for non-redirect requests today. WDY (or anyone else) T about
this approach?
Matt
> Ed
>
> --
> | edward.burns_at_oracle.com | office: +1 407 458 0017
> | homepage: | http://ridingthecrest.com/
>