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

[jsr372-experts] Re: [527-InjectFacesContext] Support and review

From: Neil Griffin <neil.griffin_at_portletfaces.org>
Date: Thu, 25 Sep 2014 10:27:38 -0400

I'm not an expert on the internals of CDI and proxying, but would it help to @Inject a singleton instance of something like this?

public class InjectableFacesContext extends javax.faces.context.FacesContextWrapper {

        @Override
        public FacesContext getWrapped() {
                return FacesContext.getCurrentInstance();
        }
}

On Sep 25, 2014, at 12:29 AM, Josh Juneau <juneau001_at_gmail.com> wrote:

> I definitely support the injection of FacesContext, and I agree that this aligns well with "CDI everywhere".
>
> Josh Juneau
> juneau001_at_gmail.com
> http://jj-blogger.blogspot.com
> https://www.apress.com/index.php/author/author/view/id/1866
>
>
> On Wed, Sep 24, 2014 at 5:22 PM, arjan tijms <arjan.tijms_at_gmail.com> wrote:
> Hi
>
> On Wed, Sep 24, 2014 at 10:20 PM, manfred riem <manfred.riem_at_oracle.com> wrote:
> since the other bean types can live longer than a request what does it mean to have a reference to a FacesContext? Or phrased a bit differently what would a FacesContext be used for outside the scope of a request?
>
> Well, it's not about using a FacesContext outside the scope of a request, it's about delegating each time to the one corresponding to the current request (and throwing an exception if there is no current request). This happens automatically in CDI when a proxy is injected (as happens for normal scoped beans).
>
> Without such proxy, CDI would inject a direct reference once and only once. With a proxy, CDI will transparently lookup the right actual reference with each call.
>
> So how did Seam solve the above problem?
>
> I'm curious to find out as well. My guess is simply a request scoped bean that implements ServletRequest and delegates to the actual ServletRequest instance.
>
> Kind regards,
> Arjan
>