1

In my web application I have a presentation Layer consisting of several jsf-viewscoped and some requestscoped beans. Normally I only want to have presentation logic in these, so whenever there's a task which goes beyond presentation logic, I use another Bean or an EJB. So in some viewscoped Beans I have an EJB injected. My question now is as follows : Should I avoid situations in which I have injected an EJB directly into a Bean used for presentation, by creating another (for example application scoped) bean which only delegates the method calls to the respective EJB ? And : When is the injected EJB initialized ? If it's initialized during the initialization of the bean it is injected into, then this would mean that for every visitor of my application there's always also an EJB reserved? I don't think thats the case but that EJBs are only used when one of its methods is called. But how should I separate business and presentation layers properly ?

4

1 回答 1

2

将 EJB 注入视图范围的支持 bean 是常见的,也是最佳实践。

(视图范围的)支持 bean 负责处理任何与视图相关的问题,并将业务逻辑委托给 EJB bean。

通常(但不一定)视图 bean 在其 PostConstruct 中从 EJB bean 加载数据,然后在回发期间保留这些数据。这对于性能和一致性都非常有益。

于 2013-05-16T09:27:54.503 回答