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

[jsr372-experts] Re: Should _at_SessionScoped Beans Allow Injection of Resources

From: arjan tijms <arjan.tijms_at_gmail.com>
Date: Sat, 4 Apr 2015 20:40:35 +0200

Hi,

On Saturday, April 4, 2015, Josh Juneau <juneau001_at_gmail.com> wrote:

> I am developing an example application to demonstrate the features of JSF
> 2.3. I've encountered what I would call an issue, a while back, as I was
> unable to inject any of the Faces CDI resources into @SessionScoped beans,
> unless I mark the injected resource(s) as transient. I have no problems
> injecting them into @Dependent or @RequestScoped beans, of course. This is
> obviously occurring because the producers are not passivation capable.
>

Indeed, I discussed this before with Manfred. It's technically as simple as
letting the producer implement that interface. After that it works. Since
the producer is request scoped CDI will create a proxy that always
delegates to the right instance.

I do have to read up on what the exact consequences are of this interface.
Last time I looked at it I didn't found it to be overly clear.

The faces context for instance is itself of course not passivisation
capable (serializable), but its producer is. After deserialisation CDI
should just create a new proxy and per request reproduce the instance.



>
>
In my opinion, there are some cases where it makes sense to utilize a
> @SessionScoped bean that contains injected resources...perhaps
> @FacesContext, for issuing a FacesMessage. While we can certainly utilize
> @RequestScoped beans that utilize @SessionScoped beans for management of
> objects that need to stay within the session, that may be cumbersome under
> some circumstances, and I can see the use case of allowing injection of
> resources into @SessionScoped beans.
>

They should be injectable in session scoped beans. From my part there is no
doubt there ;)

Thanks for mentioning it!

Kind regards,
Arjan Tijms



>
> I wanted to bring this to the expert group to see if anyone else in the
> group believes that we should allow injectable resources into
> @SessionScoped beans, as I think it may promote ease of use in some
> situations.
>
> Thanks for your time, it is appreciated.
>
> Josh Juneau
> juneau001_at_gmail.com <javascript:_e(%7B%7D,'cvml','juneau001_at_gmail.com');>
> http://jj-blogger.blogspot.com
> https://www.apress.com/index.php/author/author/view/id/1866
>
>