jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: [1361-FlowStackAndFlowScopedBeans] PROPOSAL

From: manfred riem <manfred.riem_at_oracle.com>
Date: Tue, 10 Feb 2015 15:58:56 -0600

Hi Ed,

Looking at it I think this could be locally solved by making sure the
FlowCDIContext keeps track of the depth by adding one when entering a
flow and subtracting one when exiting a flow.

Note I have not prototyped it but all the call sites to the
FlowScopeMapHelper are in FlowCDIContext.

Thanks!
Manfred

On 2/10/15, 3:29 PM, Edward Burns wrote:
> Hello Volunteers,
>
> Issue [3680-NestedFlowProblems] came up on the tracker recently. I'm
> prettry sure Leonardo has already raised this. Here is the problem.
>
> {quote}
> Consider having some flows in application, for example PersonListFlow,
> PersonDetailFlow, AddressDetailFlow
>
> Example:
> 1) enter person list - flow PersonListFlow
>
> 2) enter person detail - flow PersonDetailFlow
>
> 3) enter address detail - flow AddressDetailFlow
>
> 4) go to another person living on the same address -> flow
> PersonDetailFlow. Flow stack would be:
>
> PersonListFlow
> PersonDetailFlow
> AddressDetailFlow
> PersonDetailFlow
>
> Problem there is that FlowScoped ManagedBean is created for flow ID
> "PersonDetailFlow" and is shared with two instances of PersonDetailFlow
> in flow stack. In other words, data would be shared and after returning
> to first flow PersonDetailFlow instance they will be corrupted for the
> first person.
> {quote}
>
> The problem is the CDI context impl has no way to know that last call
> into PersonDetailFlow is a new flow-call and thus the FlowScoped beans
> from the previous invocation are visible. This is bad. The simplest
> fix is to expose the flow depth on the FlowHandler. This suggestion
> from Ren Zhijun on the JSF implementation team allows the context to
> disambiguate this case. Here is the proposal:
>
> M jsf-api/src/main/java/javax/faces/flow/FlowHandler.java
>
> - Add new method
>
> /**
> + *<p class="changed_added_2_3">Return the stack depth of flows at the point in time
> + * of invocation. For backward compatibility with older implementations,
> + * a default implementation is provided that returns 0.</p>
> + *
> + * @param context the {_at_code FacesContext} for the current request.
> + *
> + * @since 2.3
> + */
> + public int getCurrentFlowDepth(FacesContext context) {
>
> Thanks,
>
> Ed
>