A long time ago I had a very similar question: "Access SessionScoped object from stateless EJB", see here, and found a very nice answer here. But time goes on and I start to work with @ViewScoped beans and run into the same problem. How can I simulate such a view to access it from my stateless EJB? I did check for something similar as BoundSessionContext. I did find some candidates for request scoped or conversation scope, but nothing for the view scope.
Can someone help me again?
My current environment is Java 17 and Wildfly 26.1.2.
Nope. That's not possible.
The JSF View Scope is tied to the JSF View State. The JSF View State is in turn tied to the Faces Context. So you can only obtain it via the
FacesContext. And in a backend class such as EJB you should absolutely not have any frontend specific dependencies such asFacesContextas that violates the Law of Demeter. See also why shouldn't entity bean be managed by JSF framework?You need to salvage this other way. If you want to pass data from the frontend to the backend, then simply pass them as method arguments.
Or if you want to pass data from the backend to the frontend, then simply pass them as method return value.
Or if the EJB method is asynchronous, then simply pass the data via a CDI event.