[jboss-user] [EJB 3.0] - Re: Why is injection not working in AS 4.0 and 4.2 (servlets

jobor do-not-reply at jboss.com
Fri Jun 22 05:49:52 EDT 2007


There is little trick using the injection and JSF1.2 backing beans.
If you plan to use the bean during the constructor of the backing bean, that won't work.
In my backing beans I do call e.g. a find() method in the backing bean from within the constructor.
But in the old situation the first thing I did was looking up the 2.1 EJB so it was there when I needed it.
So the injection comes in later than during the execution of the constructor of the backing bean.

Old situation that does not work:
 
  | public class CatalogHandler {
  | 
  |   @EJB(name="java:comp/env/ejb/CatalogAgent") private CatalogAgentLocal agent;
  | 
  |   public CatalogHandler() {
  |     ...
  |     find();
  |   }
  | 
  |   public DataModel getCatalogModel() {
  |     return catalogModel;
  |   }
  | 
  |   public String find() {
  |     catalogModel.setWrappedData(agent.getCatalogItems(filter));
  |     ...
  |   }
  | 
  | }
  | 

The new sitiuation with a little (not very nice) trick that does work:

  | public class CatalogHandler {
  | 
  |   @EJB(name="java:comp/env/ejb/CatalogAgent") private CatalogAgentLocal agent;
  | 
  |   private boolean doInitLater = false;
  | 
  |   public CatalogHandler() {
  |     ...
  |     doInitLater = true;
  |   }
  | 
  |   public DataModel getCatalogModel() {
  |     if (doInitLater) {
  |       doInitLater = false;
  |       find();
  |     }
  |     return catalogModel;
  |   }
  | 
  |   public String find() {
  |     catalogModel.setWrappedData(agent.getCatalogItems(filter));
  |     ...
  |   }
  | 
  | }
  | 

Johan Borchers

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

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



More information about the jboss-user mailing list