Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should we found in a normal JSF session?

Tags:

session

jsf

I just noticed today that the session map contains more than what I put in.

Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
Iterator attributeNames = sessionMap.keySet().iterator(); 
while ( attributeNames.hasNext() ){
  System.out.println(attributeNames.next().toString());
}

I found two unknown objects in my session : com.sun.faces.application.view.activeViewMaps and javax.faces.request.charset. Is it normal to find those objects in the session?

I'm asking this because com.sun.faces.application.view.activeViewMaps gives me serialization errors on server restart. It looks like it tries to serialize almost everything.

Note : I know I can shut off serialization by uncommenting <Manager pathname="" /> in the server context.xml file. I just want to know if it is normal to find com.sun.faces.application.view.activeViewMaps in the session.

like image 286
ForguesR Avatar asked Mar 16 '23 23:03

ForguesR


1 Answers

Yes it's normal to find both in the session:

com.sun.faces.application.view.activeViewMaps:

Starting from JSF 2.2.0, the com.sun.faces.application.view.ViewScopeContextManager deals with CDI @ViewScoped beans, and stores the active view maps in the session with ACTIVE_VIEW_MAPS as a key (ACTIVE_VIEW_MAPS is a constant field whose value is "com.sun.faces.application.view.activeViewMaps" ), in order to keep track of them.

When the session get destroyed they will be destroyed too, you can check the source code of sessionDestroyed(HttpSessionEvent hse) from grepcode.com.

javax.faces.request.charset:

In the JSF docs you can find regarding the method public String calculateCharacterEncoding(FacesContext context) of the ViewHandler, that:

Returns the correct character encoding to be used for this request.

The following algorithm is employed.

  • Examine the Content-Type request header. If it has a charset parameter, extract it and return that as the encoding.
  • If no charset parameter was found, check for the existence of a session by calling ExternalContext.getSession(boolean) passing false as the argument. If that method returns true, get the session Map by calling ExternalContext.getSessionMap() and look for a value under the key given by the value of the symbolic constant CHARACTER_ENCODING_KEY. If present, return the value, converted to String.
  • Otherwise, return null

While CHARACTER_ENCODING_KEY is a constant field:

The key, in the session's attribute set, under which the response character encoding may be stored and retrieved.

You can get it's value from here, which is: "javax.faces.request.charset"

like image 186
Tarik Avatar answered Apr 25 '23 01:04

Tarik