Reputation: 1159
I would like to access a view scope managed bean inside a Servlet.
I searched for similar question and got these ones:
how to get beans from view scope which uses FacesContext.getCurrentInstance()
, inapplicable inside a Servlet because it should give a null result
JSF - get managed bean by name which treats all other scopes but not viewscope
I'm going to think it is not possible, is it ?
There is the simple solution to change that bean scope to session scope but it is a last chance because I'm worried by memory consumption.
My final need is the following: the managebean contains some data displayed in a dataTable. The same page should include the image (mandatory) of chart representation of those data. The image can be produced by a Servlet but it needs to access the data or reload them from the db.
I also tried the <p:graphicImage>
from PrimeFaces 2.X but it is not compatible with viewscope beans. Any suggestion?
Upvotes: 9
Views: 1990
Reputation: 1108567
That's not possible, no. The view scope is tied to a specific JSF view, which is no means of in a plain HTTP servlet request. Note that you can't access concrete request scoped beans during a plain HTTP servlet request either, they would always return null
.
The session scope is the best what you can get. You can just remove the attribute from the session scope once you're finished with it in the servlet.
session.removeAttribute("somename");
Upvotes: 7