How to access managed @ViewScoped beans from Servlets?

I want to access bean scope inside a servlet.

I searched for a similar question and got the following:

how to get beans from a viewport that uses FacesContext.getCurrentInstance() is not applicable inside a Servlet, because it should give a null result

JSF - get a managed bean by name that handles all other areas, but not viewcope

I will think that this is impossible, right?

There is a simple solution to change the bean area in the session area, but this is the last chance because I am worried about memory consumption.

My last need is this: managebean contains some of the data displayed in the dataTable. On the same page should be an image (required) displaying diagrams of this data. The image can be created by the servlet, but it needs to access the data or reload it from db.

I also tried <p:graphicImage> from PrimeFaces 2.X, but is not compatible with viewcope beans. Any suggestion?

+6
source share
1 answer

This is impossible, no. The viewport is bound to a specific JSF view, which is not a tool for a simple servlet HTTP request. Note that you cannot access a specific beans request during a simple HTTP servlet request, they will always return null .

Scope is the best you can get. You can simply remove the attribute from the session area as soon as you are done with it in the servlet.

 session.removeAttribute("somename"); 
+6
source

All Articles