[cdi-dev] [JBoss JIRA] (CDI-407) Specifiy @Named @Alternatives

Martin Kouba (JIRA) issues at jboss.org
Mon Oct 20 10:13:35 EDT 2014


    [ https://issues.jboss.org/browse/CDI-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13013498#comment-13013498 ] 

Martin Kouba commented on CDI-407:
----------------------------------

{quote}
@Named public class A
@Named @Alternative public class B extends A

What should acutally happen if B is activated via beans.xml?
{quote}
I think this is already covered in [4.1. Inheritance of type-level metadata|http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#type_level_inheritance], [5.3.1. Ambiguous EL names|http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#ambig_names] and other related sections. Note that bean names are not inherited unless specialization is used!

Regarding your example:
* bean A has a bean name "a"
* bean B has a bean name "b"
* so the names do not collide and even if you declare B as a selected alternative for a bean archive, EL expressions like #{a.foo} will not be affected, "a" will be resolved to bean A
* bean name "b" will only be resolved to bean B if it's selected

If we modify the example to:
{code:java}
@Named("a") public class A
@Named("a") @Alternative public class B extends A
{code}
* both beans have the same bean name
* if you declare B as a selected alternative, the name "a" will be resolved to bean B

> Specifiy @Named @Alternatives
> -----------------------------
>
>                 Key: CDI-407
>                 URL: https://issues.jboss.org/browse/CDI-407
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Beans, Inheritance and Specialization
>            Reporter: Thomas Andraschko
>
> It's actually a must-have for product development and a common case.
> We would like to have multiple implementations in our core and just activate them via alternative.
> I talked with struberg and its currently not defined in the specs.
> e.g.
> @Named public class A
> @Named @Alternative public class B extends A
> What should acutally happen if B is activated via beans.xml?
> IMO B should be available in EL via "a" and "b".



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the cdi-dev mailing list