jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] JSF API to extract component state from view state, and to physically remove view state from server side state

From: Bauke Scholtz <balusc_at_gmail.com>
Date: Thu, 21 Jul 2016 15:29:08 +0200

Hi,

During working on "immediately destroy bean instance and server side view
state on page unload" feature of OmniFaces @ViewScoped, I stumbled upon two
shortcomings in public JSF API.


1. There is no clean way to restore only the state of a specific component.
The ResponseStateManager#getState() returns the entire view state while I'd
like to restore only the component state of UIViewRoot instance itself. See
also
https://github.com/omnifaces/omnifaces/blob/da3847ff41f93e2a4f847eb2176c2343a32b968b/src/main/java/org/omnifaces/viewhandler/OmniViewHandler.java#L141
In other words, there is no JSF API provided way to obtain exactly the part
of the view state as expected by 2nd argument of
UIComponent#restoreState().

I'm only not exactly sure if adding a public API on that would be a great
idea. Perhaps we should leave it, but just throwing here for thoughts.


2. There is no JSF API provided way to physically remove the entire view
state from the server side state. See also:
https://github.com/omnifaces/omnifaces/blob/296c4d03f47a8d69360f14ef74c5d6e3fe243ff6/src/main/java/org/omnifaces/util/Hacks.java#L362


I'd expect to see a ResponseStateManager#destroyViewState() or
#removeViewState() taking FacesContext argument which does exactly the task
of destroying/removing the server side view state associated with the
currently set view root. This could also be called by the implementation
directly after PreDestroyViewMapEvent, just for more optimal memory usage,
and also a more robust LRU sequence of view states in Mojarra.


What do you guys think?

Cheers, B