Hi Experts - Our business (service) layers lives within OpenEJB on a remote host. Most of our business logic (DAOs, etc) are stateless session beans. We were able to elegantly define them as Tapestry services using standard static module builder. Here is our (simplified) EjbModule with one statless EJB:
/** * Defines all aspect of EJB remoting. Each EJB becomes a singleton * Tapestry IOC service, and can be used from a page or component * via @Inject or @InjectService. * * @author Adam Zimowski */ public class EjbModule { private static final Logger log = LoggerFactory.getLogger(EcommerceModule.class); public static Context buildEjbContext(@Inject @Value("${ejb.host}") String aEjbHost) { if(log.isDebugEnabled()) log.debug("EJB host: " + aEjbHost); Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); p.put(Context.PROVIDER_URL, aEjbHost); Context ctx = null; try { ctx = new InitialContext(p); } catch(NamingException ne) { log.error("EJB host lookup error!", ne); } return ctx; } public static CatalogServiceRemote buildCatalogService(@InjectService("EjbContext") Context aEjbContext) { CatalogServiceRemote catalogService = null; try { Object ref = aEjbContext.lookup("CatalogServiceEjbRemote"); catalogService = (CatalogServiceRemote)PortableRemoteObject.narrow(ref, CatalogServiceRemote.class); } catch(NamingException ne) { log.error("Unable to create " + CatalogServiceRemote.class.getSimpleName(), ne); } return catalogService; } } Works perfectly. In a page or component we simply do: @InjectService("CatalogService") private CatalogServiceRemote catalogService; and we're talking to a statless EJB on a remote host. Things become a bit tricky with a statfull session bean. I don't see how I can use the same approach since I now need to retain a state meaning I need to hold onto a specific EJB instance per request. What's the preferred and recommended way to use statefull session beans within a Tapestry application? The closest I've got was to define some sort of a factory, and store the proxy in the HttpSession. May work, but so ugly comparing to our elegant solution with statless beans. Any ideas highly appreciated. Adam --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org