3 Replies Latest reply on Jul 29, 2009 8:41 PM by asookazian

    Declaration of seam components

      Hello everyone!


      I would like to have some help to declare seam components withing a class.  I need to declare the class CalendarDataModelItemImpl as a class and as an array of the class.


      The class CalendarDataModelItemImpl:


      @Name("calendarDataModelItemImpl")
      public class CalendarDataModelItemImpl implements CalendarDataModelItem, Serializable{ ..}




      It is accessed from another class in this way :


             @In(create=true)
              private CalendarDataModelItem calendarDataModelItemImpl;



      I need to instantiate an array of the class CalendarDataModelItemImpl


      How should i declare the array of the CalendarDataModelItemImpl  in seam?


      Anyone has an idea about that?

        • 1. Re: Declaration of seam components
          cash1981

          I am not sure what you are talking about here, but it is nothing seam specific to create an array or list.



          I guess you can create an array like this, however I discourage you from using Arrays and using List instead.


           @In(create=true)
            private CalendarDataModelItem[] calendarDataModelItemImpl;



          • 2. Re: Declaration of seam components

            I agree with Shervin, it´s better for you to use Java 5 collections.
            For instance, if ArrayList suits you:


             @In(create=true)
             private ArrayList<CalendarDataModelItem> list = new ArrayList<CalendarDataModelItem>();
            




            • 3. Re: Declaration of seam components
              asookazian

              The only time I use arrays in Seam apps is when I have to.


              Example:


              List<Object[]> list = entityManager.createQuery("select c, o from Customer c, Order o where o.customer.customerId = c.customerId and o.orderId = :orderId")
              .setParameter("customerId", customerId)
              .setParameter("orderId", orderId)
              .getResultList();



              When there is more than one entity in the select clause, the JPA provider returns a Object[].


              Otherwise, try to use the following pattern:


              List<foo> list = new ArrayList<foo>();



              Same thing applies for Sets:


              Set<foo> set = new HashSet<foo>();



              interface on the left side, concrete implementation on the right side to support polymorphism (e.g. you can swap in a LinkedList for the ArrayList later if required).