1

My problem is probably best explained with some sample code:

@Named
public class Search {
    @Inject @Select(Type.SEARCH)
    private Criteria criteria;
}

@Named
public class Selection {
    @Inject @Select(Type.SELECTION)
    private Criteria criteria;
}

public class Criteria {
    private final List<Selection> statics;
    private final List<Selection> choosables;

    @Inject
    public Criteria(
            @Any Instance<List<Selection>> statics,
            @Select(Type.CHOOSABLE) List<Selection> choosables,
            InjectionPoint ip) {
        Select sel = ip.getAnnotated().getAnnotation(Select.class);
        this.statics = cloneList(statics.select(sel).get());
        choosables = cloneList(choosables);
    }
}

The idea is that Criteria has all the logic to deal with lists of Selection objects, but the actual lists to manage vary depending on the user of the Criteria class. As it stands, Weld complains about being unable find a class with the matching qualifiers, since Criteria isn't annotated @Select. So - can I make Criteria eligible for injection no matter the @Select qualifier? Or is there another way to pass that piece of information to the Criteria class?

Edit: turns out, the question has already been asked in a similar form here.

Community
  • 1
  • 1
mabi
  • 5,279
  • 2
  • 43
  • 78
  • Not sure tot totally understand your use case. What you want is a `Criteria` bean that could be injected for whatever qualifier on InjectionPoint. Is that it ? Are you using CDI 1.0 or 1.1 ? – Antoine Sabot-Durand Dec 12 '13 at 22:14
  • @AntoineSabot-Durand yeah, that would help. Basically, I'd use this to simulate "pass an argument to the constructor" to switch the data source that `Criteria` uses. I'm using Wildfly-8.Beta1, so this is CDI-1.1. – mabi Dec 13 '13 at 08:49

0 Answers0