문제

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 ?

도움이 되었습니까?

해결책

Injecting an EJB into a view scoped backing bean is common and a best practice.

The (view scoped) backing bean takes care of any view related concerns, and it delegates to the EJB bean for business logic.

Often (but not necessarily) a view bean loads data from an EJB bean in its PostConstruct, which it then holds on to during postbacks. This can be very benificial for both performance and consistency.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top