dev@javaserverfaces.java.net

Re: Please help: CDI definition failure:WELD-000409: Observer method for container lifecycle event

From: arjan tijms <arjan.tijms_at_gmail.com>
Date: Tue, 15 Sep 2015 00:03:01 +0200

Hi,

On Mon, Sep 14, 2015 at 11:17 PM, Edward Burns <edward.burns_at_oracle.com> wrote:
>>>>>> On Fri, 11 Sep 2015 20:51:33 +0200, arjan tijms <arjan.tijms_at_gmail.com> said:

> Please find attached a changebundle that rewrites the processBean() to
> not use lambda. If it's ok with you, please let me know and I'll commit
> it.

I already had nearly the same change queued locally, but was waiting
for review of a couple of other commits to the same file (for which
the change bundles have to be created serialised because of changes to
the same file).

Anyway, the change itself is okay. One thing is that checking Optional
for null is not needed. The method never returns null (although JDK8
best practices still have to be firmly established, I believe that
returning null for an Optional is rather bad practice).

But would be great if you could wait a little with this commit until
the commit for 1391 has been done. If it actually needs to be
committed as soon as possible then go ahead and I'll sort out the
commit conflict here locally.

Kind regards,
Arjan Tijms


>
> Thanks,
>
> Ed
>
>
> --
> | edward.burns_at_oracle.com | office: +1 407 458 0017
> | 38 Business days til JavaOne 2015
> | 53 Business days til DOAG 2015
>
> Don't use lambda in processBean() since Weld doesn't like it.
>
> SECTION: Modified Files
> ----------------------------
> M jsf-ri/src/main/java/com/sun/faces/cdi/CdiExtension.java
>
>
> SECTION: Diffs
> ----------------------------
> Index: jsf-ri/src/main/java/com/sun/faces/cdi/CdiExtension.java
> ===================================================================
> --- jsf-ri/src/main/java/com/sun/faces/cdi/CdiExtension.java (revision 15195)
> +++ jsf-ri/src/main/java/com/sun/faces/cdi/CdiExtension.java (working copy)
> @@ -47,6 +47,7 @@
> import java.util.LinkedHashMap;
> import java.util.List;
> import java.util.Map;
> +import java.util.Optional;
>
> import javax.enterprise.event.Observes;
> import javax.enterprise.inject.spi.AfterBeanDiscovery;
> @@ -105,17 +106,13 @@
> @SuppressWarnings("unchecked")
> public <T extends DataModel<?>> void processBean(@Observes ProcessBean<T> event, BeanManager beanManager) {
>
> - // Collect all classes annotated by @FacesDataModel in a Map
> - // Key: (collection) class that a DataModel implementations wraps
> - // Value: the DataModel implementation class
> -
> - getAnnotation(beanManager, event.getAnnotated(), FacesDataModel.class)
> - .ifPresent(d ->
> - forClassToDataModelClass.put(
> - d.forClass(),
> - (Class<? extends DataModel<?>>) event.getBean().getBeanClass()
> - )
> - );
> + Optional result;
> + result = getAnnotation(beanManager, event.getAnnotated(), FacesDataModel.class);
> + if (null != result && result.isPresent()) {
> + FacesDataModel d = (FacesDataModel) result.get();
> + forClassToDataModelClass.put(d.forClass(),
> + (Class<? extends DataModel<?>>) event.getBean().getBeanClass());
> + }
> }
>
> /**
>
>
>