Frage

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 ?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top