Search code examples
jsfjsf-2.2omnifacesview-scope

How do I count the number of views in a user's JSF session (JSF 2.2)?


I'm trying to track view usage (coming up against the default 15-count limit) but not quite sure where to get this information. Is it available in FacesContext somewhere?

Using JSF 2.2, ICEfaces 3.3, and Omnifaces 2.2.


Solution

  • It's implementation specific and only available when server side state saving is used.

    Based on your question history and your related OmniFaces issue report, I gather that you're using GlassFish and thus Mojarra. The physical views are available as a session attribute keyed by com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap.

    Thus, so:

    Map<String, Map<String, Object[]>> physicalViews = Faces.getSessionAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap");
    String numberOfViews = physicalViews.size();
    // ...
    

    Note that Mojarra unintentionally swapped the meaning of "physical views" and "logical views" in both the context parameter names and the codebase. So, the max size of the above map (the physical views) is configurable by com.sun.faces.numberOfLogicalViews and the max size of the nested map (the logical views) is configurable by com.sun.faces.numberOfViewsInSession.

    See also: