[jboss-user] [JBoss Seam] - Question on Injecting

hasc do-not-reply at jboss.com
Thu Mar 29 09:15:28 EDT 2007


Hello,

i got a question on how to inject a component.

i've got a class that loads database objects.



@Stateful
  | @Name("ItemsCache")
  | public class ItemsCacheBean implements ItemsCache, Serializable {
  | 
  |     @PersistenceContext 
  |     EntityManager em;
  | 	
  |     private List<MyObjects> items;
  | 	
  |     @Create
  |     public void cacheObjects() {
  |         items = em.createQuery("select . from Object o")
  |         .setHint("org.hibernate.cacheable", true)
  |         .getResultList();
  |     }
  | 	
  |     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:



@Stateful
  | @Name("itemsmanager")
  | 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) {
  |             results.put(myobject.getName(locale),myobject);
  |         }
  |         
  |         objectsMap = results;	
  |         return objectsMap;
  |     }
  | 	
  |     public Converter getConverter()
  |     {
  |         return new MyObjectsTypeConverter(itemscache.getItemsList(););
  |     }
  | 	
  |     @Remove @Destroy 
  |     public void destroy() {}
  | }


regards,
hasc

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4032756#4032756

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4032756



More information about the jboss-user mailing list