5 Replies Latest reply on Mar 29, 2007 9:58 AM by Hannes Schulz

    Question on Injecting

    Hannes Schulz Newbie


      i got a question on how to inject a component.

      i've got a class that loads database objects.

      public class ItemsCacheBean implements ItemsCache, Serializable {
       EntityManager em;
       private List<MyObjects> items;
       public void cacheObjects() {
       items = em.createQuery("select . from Object o")
       .setHint("org.hibernate.cacheable", true)
       public List<MyObjects> getItemsList(){
       return items;
       @Remove @Destroy
       public void destroy() {}

      now in another bean i want to get the list of objects once, ant then serve it as listitems where the label of the displayed item depends on the locale whenever a clients requests it. i tried the following:

      public class ItemsManagerBean implements ItemsManager, Serializable {
       @In(create=true) ItemsCache itemscache;
       @In Locale locale;
       Map<String,MyObject> objectsMap;
       public Map<String,MyObject> getObjects()
       List<MyObjects> items = itemscache.getItemsList();
       String locale = this.locale.toString();
       Map<String,MyObject> results = new TreeMap<String,MyObject>();
       for (MyObject myobject: items) {
       objectsMap = results;
       return objectsMap;
       public Converter getConverter()
       return new MyObjectsTypeConverter(itemscache.getItemsList(););
       @Remove @Destroy
       public void destroy() {}