4 Replies Latest reply on Oct 18, 2009 3:30 PM by gavin.king

    Web Beans Collections Lists Maps Sets

      I have realized that web beans doesn't have a default support for Collections. For instance, web beans doesn't instantiate an java.util.ArrayList (default) when I have:

      @Curren private List<Date> dates;

      And I couldn't build a factory generic enough to support any collection.

      I think collections aren't web beans, are they?
      So if a want to put a collection proprerty in Session Scope, for instance, I should put it inside a bean, right?

      How does web beans deal with collections?

        • 1. Re: Web Beans Collections Lists Maps Sets

          I don't really understand what you are asking. Try to be more concrete, less abstract.

          Given that the only way you interact with scopes in CDI is via beans, no, you can't put a collection property into the session.

          If you are asking how you write a producer method which will provide a bean to inject into your field:

          @Produces List<Date> getDates() {
             return new ArrayList<Date>();
          @Inject List<Date> dates;

          • 2. Re: Web Beans Collections Lists Maps Sets

            Collections arent't web beans. I got it.
            So, I shouldn't work with a collection inside a scope, right?

            • 3. Re: Web Beans Collections Lists Maps Sets

              Well you could certainly use a collection as a bean - as I showed above :-)

              • 4. Re: Web Beans Collections Lists Maps Sets

                You can't write @Inject List<Something> unless you have defined a bean which implements List<Something> and put it in a bean deployment archive. This is the case for any interface, nothing special about collections here. Lots of classes implement List, there's no way we can assume it is an ArrayList.

                Nor can you just write @Inject ArrayList<Something>, since the class ArrayList is not in a bean deployment archive - and anyway, I'm not quite sure what the value of injecting an empty ArrayList would be.

                However, if all you are trying to do is just inject a new array list with no members, you can write:

                @Inject @New(ArrayList.class) List<Something>

                However this does not yet work in the current release of Weld. Pete is working on it.