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 as FacesContext
as 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.
@Named
public class YourBackingBean {
@Inject
private YourServiceBean yourServiceBean;
public void someActionMethod() {
// ...
yourServiceBean.someServiceMethod(theseArguments);
}
}
Or if you want to pass data from the backend to the frontend, then simply pass them as method return value.
@Named
public class YourBackingBean {
@Inject
private YourServiceBean yourServiceBean;
public void someActionMethod() {
SomeObject thisResult = yourServiceBean.someServiceMethod();
// ...
}
}
Or if the EJB method is asynchronous, then simply pass the data via a CDI event.
@Stateless
public class YourServiceBean {
@Inject
private BeanManager beanManager;
@Asynchronous
public void someAsyncServiceMethod() {
// ...
beanManager.getEvent().select().fire(thisResult);
}
}
@Named
public class YourBackingBean {
public void observerMethod(@Observes SomeObject thisResult) {
// ...
}
}