Skip to main content

Inconsistent firing of PreDestroyViewMapEvent

2 replies [Last post]
pejovica
Offline
Joined: 2010-03-15

Hi,

lets say that we have a facelet view index.xhtml with following command links:

If I follow the first command link PreDestroyViewMapEvent will fire, but if I follow the second one it won’t. So, I was wondering does anyone know if there is a reason for this difference in behavior.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ed Burns

>>>>> On Mon, 28 Jun 2010 10:16:11 PDT, webtier@javadesktop.org said:

P> lets say that we have a facelet view [b]index.xhtml[/b] with
P> following command links:

P>
P>

P> If I follow the first command link PreDestroyViewMapEvent will fire,
P> but if I follow the second one it won'tt. So, I was wondering does
P> anyone know if there is a reason for this difference in behavior.

This is because in the first case, you are doing a POSTBACK, which
causes the navigation to happen during the invoke application phase,
which changes the viewId stored in the FacesContext during the POSTBACK
lifecycle run.

In the second case, you're doing a POST REDIRECT GET, which encompases
multiple runs through the lifecycle, each with its own FacesContext
instance.

Let's look at the HTTP traffic in both cases.

P>

Client Server

POST index.xhtml run lifecycle phases APPLY_REQUEST_VALUES upto
and including INVOKE_APPLICATION on one
FacesContext.
During INVOKE_APPLICATION, a new UIViewRoot is
created as a result of the navigation. It
happens have the same viewId because you
manually specify "index" as your action, but
it's a new UIViewRoot just the same. When this
viewId is populated into the FacesContext, the
viewMap is destroyed.
Run RENDER_RESPONSE phase, send response to client

P>

Client Server
POST index.xhtml same as above, but do not run RENDER_RESPONSE
phase. Instead send 302 redirect.
GET index.html This is a new request, with a new FacesContext,
so we don't get the viewmap destroyed event.

Ed

--
| edburns... | office: +1 407 458 0017
| homepage: | http://ridingthecrest.com/
| 13 Work Days Til JSF 2.1 Milestone 1

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

pejovica
Offline
Joined: 2010-03-15

I agree with everything stated above, so I'll try to rephrase my question in light of your answer.

> P>
>
> Client Server
> POST index.xhtml same as above, but do not run RENDER_RESPONSE
> phase. Instead send 302 redirect.

I've observed that in POST run of PRG when redirect 302 is sent, PreDestroyViewMapEvent is fired every time except when redirect is targeting the same page. So, why is that? Why PreDestroyViewMapEvent isn't fired only when PRG is targeting the same page from which it has originated? Hope I've made more sense this time. :)