[cdi-dev] How about documenting Alternatives on producers ?
antonio.goncalves at gmail.com
Tue Oct 21 12:47:58 EDT 2014
BTW, if I take the @Alternative producer out (so there is no more
@Alternative) but leave the <alternative> element, the Weld error message
WELD-001422: Enabled alternative
<class>org.agoncal.cdi.PrefixProducer</class> in file:/beans.xml at 7 is not
Again, the error message is very "bean" oriented, don't you think ?
On Tue, Oct 21, 2014 at 4:10 PM, Antonio Goncalves <
antonio.goncalves at gmail.com> wrote:
> Hi all,
> I often use code such as the one below: one bean, two producers and one
> producer is an alternative (not the bean) :
> *public class *PrefixProducer
> *public *String *prefixNonAlt *= *"non-alternative"*;
> * @Alternative*
> *public *String *prefixAlt *= *"alternative"*;
> I enable the alternative, as usual, by declaring the bean in the beans.xml
> This works fine, no problem. But I just realized that Intellij IDEA
> displays the warning "Alternative class expected here". I've looked around,
> read the spec, the Weld documentation, and didn't find any example of the
> code above. I think people are unware of this. The only reference of
> alternative producers I found is in the spec :
> *An alternative is selected for the bean archive if either:*
> ** the alternative is a producer method, field or resource, and the bean
> class that declares the method or field is listed*
> I think for such easy use cases (i.e PrefixProducer) there is no need to
> multiply beans, so the code is fine and easy to read. But the code you see
> around, tend to multiply beans (people think that Alternatives are *only*
> for beans, not for producers).
> Shouldn't the spec/Weld documentation mention this case a bit more often,
> by giving an example ?
> WDYT ?
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2 (
> http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
Software architect, Java Champion and Pluralsight author
Web site <http://www.antoniogoncalves.org> | Twitter
<http://twitter.com/agoncal> | LinkedIn <http://www.linkedin.com/in/agoncal> |
<http://pluralsight.com/training/Authors/Details/antonio-goncalves> | Paris
JUG <http://www.parisjug.org> | Devoxx France <http://www.devoxx.fr>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cdi-dev