Should EJBs be instance variables and marked as transient in JSF Managed Beans?

你说的曾经没有我的故事 提交于 2020-01-15 05:22:20

问题


We have several JSF Managed beans with Request, View, and Session Scope and are running WebLogic 11g (10.3.2). Weblogic does not support the @EJB annotation in a JSF Managed Bean, so we have used these procedures http://technology.amis.nl/2008/12/06/ejb-dependency-injection-of-session-bean-facade-in-jsf-12-on-weblogic-103-jsf-with-jpa/ to create a ServletConextListener to load EJB references using the @EJB annotation.

Effectively, from within the JSF Managed Bean, we are then able to look up the EJB interface for the EJB that we wish to use by getting it from the ServletContext.

So the questions are:

1) Is it OK to make an EJB interface an instance variable on a ManagedBean? (the rationale is that the EJB is called many times during a page cycle)

2) if we do make them instance variables, should we mark the EJB Interfaces instance variables as transient?


回答1:


1) Is it OK to make an EJB interface an instance variable on a ManagedBean? (the rationale is that the EJB is called many times during a page cycle)

That's the normal design, yes. It's not different from when using @EJB. The returned EJB instance is a proxy anyway. The proxy will in turn worry about delegating the method calls to the proper and available concrete EJB instance in the EJB pool of the container.

Your only concern may be @Stateless versus @Stateful as seen relative to the JSF managed bean scope. You need to really understand what each the EJB session stands for. The @Stateless may return you a random instance on every call. The @Stateful gives you the same instance as long as the client (in this particular case, the JSF managed bean instance) lives. A more in depth explanation can be found here: JSF request scoped bean keeps recreating new Stateful session beans on every request?


2) if we do make them instance variables, should we mark the EJB Interfaces instance variables as transient?

Not needed. The EJB proxy is by default already serializable.



来源:https://stackoverflow.com/questions/9823300/should-ejbs-be-instance-variables-and-marked-as-transient-in-jsf-managed-beans

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!