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?
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With