Inject ConversationScoped beans within an asynchronous method

I need to call a method annotated with @Asynchronous in EJB from a ConversationScoped bean. Inside this method I create instances of some classes using @Inject to inject ConversationScoped beans. Is it somehow possible to set the context of the asynchronous method to given Conversation?

I hope you can help me.

Answers


No, absolutely not. EJBs do per definition not run in web container, but in EJB container. In essence, having any web-related artifact/dependency (including javax.faces.* classes) inside an EJB class is a red alert. You're not supposed to inject/access any class from the client tier (the WAR) in the business tier (the EJB/EAR). Moreover, conversation scoped beans are tied to a HTTP request parameter and this information is nowhere available in an EJB container.

Whatever problem you're trying to solve and for which you incorrectly thought that this all would be the right solution, it has to be solved differently. As an educated guess, I think you just need to let the EJB fire a CDI event or take a callback argument.

See also:

Need Your Help

How to display an image based on SelectedValue in a GridView?

c# asp.net image gridview

I have built some back-end code to retrieve an image from a SQL Server database. I want to display this image on my web form based on the currenct selected value of a gridview control.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.