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

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

From: manfred riem <manfred.riem_at_oracle.com>
Date: Thu, 15 Dec 2016 10:45:06 -0700

Hi Leonardo,

Because CDI is the preferred way going forward we need to understand
that comes
at a cost and since the initialization of CDI is at best tricky I would
have to push back
hard on trying to make the "initialization" FacesContext available.

If someone needs to bootstrap something during initialization and they
want to use
CDI they should use CDI specific means for it.

So from my end this would be a -1.

Thanks!

Kind regards,
Manfred Riem

On 12/15/16, 10:22 AM, Leonardo Uribe wrote:
> Hi
>
> It is very easy to make a new CDI scope, because in JSF we have
> already made
> other scopes, so it is just copy/paste. It would take only hours to
> make the scope,
> once we have defined the annotations to include. I created a custom
> @FacesScoped annotation in that time, so I have no doubts.
>
> In JSF there are two events: PostConstructApplicationEvent and
> PreDestroyApplicationEvent, so I guess an scope can be created over
> these two
> events.
>
> I can't touch Mojarra code, but I can give it a try in MyFaces and
> commit the code
> there, and then tell you guys to do the magic in Mojarra. I think with
> about two
> months there is plenty of time to do it.
>
> regards,
>
> Leonardo Uribe
>
> 2016-12-15 11:47 GMT-05:00 arjan tijms <arjan.tijms_at_gmail.com
> <mailto:arjan.tijms_at_gmail.com>>:
>
> Hi,
>
> On Thu, Dec 15, 2016 at 6:39 AM, Leonardo Uribe
> <leonardo.uribe_at_irian.at <mailto:leonardo.uribe_at_irian.at>> wrote:
>
> 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.
>
>
> True, true, so luckily the CDI application scope doesn't
> automatically overtakes the existing JSF one.
>
> I have to say that the "fake/startup" FacesContext has been some
> source of issues. In hindsight, perhaps it should not have been
> there in the first place. If this view is supported by the other
> EG members it may be a good thing that this will not be available.
>
> There's a couple of solutions here though. One is that after the
> spec is released, third party libraries like OmniFaces fill this
> void by providing a producer for this special startup
> FacesContext. There's a precedence for that, as in previous steps
> to move to CDI, the JSF spec also omitted some features (like e.g.
> a CDI @ViewScoped).
>
> The other is that someone puts in the work to create such producer
> now. The time we have left is short though, and the available
> resources likely low. If you'd like to give it a try though,
> please do. If you can't finish the work before the spec is final
> you could perhaps use it as a MyFaces specific feature and then we
> put it in the spec next time.
>
>
> 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.
>
>
> The JavaDoc should be there, it's:
>
> /**
> * <p class="changed_added_2_3">The presence of this annotation (along
> * with {_at_code @Inject}) on a field of any type causes the value
> returned from
> * evaluating an expression language expression to be
> * injected as the value of that field. </p>
> */
>
> @Qualifier
> @Target(FIELD)
> @Retention(RUNTIME)
> public @interface ManagedProperty {
> /**
> * <p class="changed_added_2_3">Taken to be the value that is
> injected into
> * the field. </p>
> *
> * @return the value.
> */
> @Nonbinding
> String value();
> ...
>
> Kind regards,
> Arjan Tijms
>
>
>
>
> regards,
>
> Leonardo Uribe
>
>
> 2016-12-14 12:56 GMT-05:00 arjan tijms <arjan.tijms_at_gmail.com
> <mailto:arjan.tijms_at_gmail.com>>:
>
> Hi Leo,
>
> On Wed, Dec 14, 2016 at 12:19 AM, Leonardo Uribe
> <leonardo.uribe_at_irian.at <mailto: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
> <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
> <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
> <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
> <http://arjan-tijms.omnifaces.org/p/jsf-23.html#1418>
>
> Hope this cleared things up.
>
> Kind regards,
> Arjan Tijms
>
>
>
>
> regards,
>
> Leonardo Uribe
>
>
>
>
>