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

[jsr372-experts] Re: [jsr372-experts mirror] Re: Features from JSF Managed Beans not present in CDI

From: Leonardo Uribe <leonardo.uribe_at_irian.at>
Date: Thu, 15 Dec 2016 00:39:01 -0500

Hi

AT>> This feature is largely provided by CDI natively, namely via the
AT>> @Observes @Initialized(ApplicationScoped.class) construct.

AT>> Going beyond the spec, there's third party support for eagerly
AT>> instantiating CDI beans via OmniFaces:

I'm afraid these solutions are not good enough. The reason is the lifecycle
of
@ApplicationScoped is longer than JSF Application lifecycle.

In other words, JSF Managed Bean Application Scope ensures there is a
valid FacesContext instace on @PostConstruct and @PreDestroy. CDI
Application Scope does not ensures that, so code that rely on get a
FacesContext instance at startup will no longer work if managed beans
are deprecated, or at least this part of the code can't be migrated
properly to CDI.

This is a migration problem. If the EG is serious about deprecate managed
beans, this problem should be handled, even if this means create another
CDI application scope for JSF.

For example, JSF @ViewScoped has some lines that says this:

"... In the session expiration case, the runtime must ensure that
FacesContext.getCurrentInstance() returns a valid instance if it is called
during the processing of the @PreDestroy annotated method. ..."

This is important because there are tons of lines of code that relies on
be able to get a FacesContext instance at startup/shutdown.

Please remember traditionally, JSF depends on servlet context /
portlet context to be initialized through ExternalContext interface. But at
the time CDI becomes more relevant and a more stronger dependency, it starts
to make sense to initialize some parts of JSF as a CDI extension instead.
But this is maybe not possible, because at CDI startup, there is no way to
get a servletContext or portletContext instance that is required to
initialize
JSF and create a FacesContext instance.

So, the easy way is "yet another CDI application scope for JSF".

AT>> There's a direct CDI replacement for that provided by JSF 2.3. It's in
AT>> the javax.faces.annotation package.

Ok, it is not yet in the javadoc. Thanks for the link, that gives me an
idea about how it will work.

regards,

Leonardo Uribe


2016-12-14 12:56 GMT-05:00 arjan tijms <arjan.tijms_at_gmail.com>:

> Hi Leo,
>
> On Wed, Dec 14, 2016 at 12:19 AM, Leonardo Uribe <leonardo.uribe_at_irian.at>
> wrote:
>
>> - Is there any plans to include an @Eager annotation or something similar
>> in order to provide the same behavior for @ManagedBean(eager="true")?
>>
>
> This feature is largely provided by CDI natively, namely via the @Observes
> @Initialized(ApplicationScoped.class) construct. See Romain's blog post
> about this here: https://rmannibucau.wordpress.com/2015/03/10/cdi-
> and-startup
>
> There's also a CDI issue for this specifically here: https://issues.jboss.
> org/browse/CDI-473
>
> Going beyond the spec, there's third party support for eagerly
> instantiating CDI beans via OmniFaces: http://showcase.
> omnifaces.org/cdi/Eager
>
>
>
>> - Is there any plans to include something similar to
>> @ManagedProperty(value="#{mybean}"), or we will rely on what @Inject
>> already provides?
>>
>
> There's a direct CDI replacement for that provided by JSF 2.3. It's in the
> javax.faces.annotation package. See http://arjan-
> tijms.omnifaces.org/p/jsf-23.html#1418
>
> Hope this cleared things up.
>
> Kind regards,
> Arjan Tijms
>
>
>
>
>
>>
>> regards,
>>
>> Leonardo Uribe
>>
>
>