I don’t look at the Mojarra code to make sure that everything I write at MyFaces is really ‚clean room‘. But from just taking a brief look at this class, yes, I think it’s simply a small bug. Not a big deal, but just a smallish bug.
And of course we (CDI EG) could probably describe the problem better.
Imo in practise ALL Bean<T> implementations for a NormalScope must implement PassivationCapable. This is not required by the spec but a logical consequence of how CDI is designed.
There are 3 different mechanics involved
1.) Serialisation of the Contextual Instance. This only affects if the NormalScoped is passivating=true (like @SessionScoped, @ViewScoped). This happens if the ’storage’ for that context gets moved to another cluster, etc. The spec is really clear on this one.
But the next 2 are only ‚indirectly defined‘
2.) Serialisation of the Contextual Reference. This is what blows up in your case. And it is independent on whether your own contextual instance gets serialized or not. Consider an @ApplicationScoped MyService which is not serializable. And now you inject this into a @SessionScoped MyView. When MyView gets serialized (cluster) then the proxy for MyService which got injected into MyView gets serialized as well. And this proxy (the Contextual Reference) just serializes the passivationId over to the other node. We cannot serialize the whole Bean<T> as it usually contains refs to a lot of Class<?>, Method<?>, Field<?> etc. On the other node this gets ‚connected‘ to the Bean<T> again via BeanManager#getPassivationCapableBean(String id)
3.) Injecting a @Dependent bean into a passivating scoped bean. E.g. injecting an @Dependent MyStateHelper into a @ViewScoped JsfBackingBean. In that case the Bean<MyStateHelper> gets stored in the CreationalContext of your JsfBackingBean. And this gets serialized along to the Client or other node with the ViewContext…
Hope that helps a bit.
LieGrue,
strub
> Am 05.04.2015 um 22:49 schrieb arjan tijms <arjan.tijms_at_gmail.com>:
>
> Hi,
>
> On Sunday, April 5, 2015, Mark Struberg <struberg_at_yahoo.de> wrote:
>
> > Am 05.04.2015 um 21:07 schrieb arjan tijms <arjan.tijms_at_gmail.com>:
> >
> > If this does not implement javax.enterprise.inject.spi.PassivationCapable (http://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/PassivationCapable.html) then the injection in session scoped beans fails.
> >
>
> Yes, and that is simply a bug. There is nothing wrong with CDI in general, just a simple bug in Mojarra.
>
>
> Just to be sure, do you mean it's a bug in Mojarra that the FacesContextProducer does not implement the PassivationCapable interface?
>
> Kind regards,
> Arjan Tijms
>
>
>
>
> Ed, feel free to ping me and I’ll explain. Or we sit together over a coffee next week and I help you fixing this.
>
> LieGrue,
> strub