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

[jsr372-experts] Re: [JAVASERVERFACES_SPEC_PUBLIC-1056] DISCUSSION - More flexible state saving

From: arjan tijms <arjan.tijms_at_gmail.com>
Date: Mon, 14 Dec 2015 22:47:53 +0100

Hi,

On Fri, Dec 11, 2015 at 6:00 PM, Edward Burns <edward.burns_at_oracle.com>
wrote:

> >>>>> On Thu, 10 Sep 2015 16:36:16 +0200, arjan tijms <
> arjan.tijms_at_gmail.com> said:
>
> AT> Hi,
> AT> As requested in the closed issue, I've created the following smaller
> issues:
>
> AT> * https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1405 -
> AT> State saving per pattern
> AT> * https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1406 -
> AT> Unify "none" with "server" and "client"
> AT> * https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1407 -
> AT> State options for @Viewscoped
>
> AT> Thoughts?
>
> Well, I'm glad these have been broken out into separate issues, but I
> would like to see some concrete proposals for them.
>

The proposal for 1405, state saving per pattern, is to have a setting that
specifies a URL pattern. In faces-config.xml this could look approximately
like this:

<state-saving>
        <method>client</method>
        <url-pattern>/public/*</url-pattern>
</state-saving>

Then
in javax.faces.application.StateManager.isSavingStateInClient(FacesContext)
the code could first check if there are per pattern rules at all, and cache
this decision. If there are no per pattern rules, skip directly to the code
as it is now. If there are pattern rules, resolve the current URL against
those patterns, and possibly cache the outcome.

In pseudo code something like:

    public boolean isSavingStateInClient(FacesContext context) {
       if (arePerPatternRules == null) {
           arePerPatternRules = ...;
       }

       if (!arePerPatternRules) {
           return isGlobaballySaveStateInClient();
       }

       Pattern pattern = patternCache.get(...);
       if (pattern == null) {
           pattern = matchPattern(...);
           patternCache.put(..., pattern);
       }

       if (pattern.isMatch()) {
           return pattern. isSavingStateInClient()
       }

       return isGlobaballySaveStateInClient(context);
    }

 private boolean isGlobaballySaveStateInClient(FacesContext context) {
    if (null != savingStateInClient) {
            return savingStateInClient.booleanValue();
        }
        savingStateInClient = Boolean.FALSE;

        String saveStateParam = context.getExternalContext().
              getInitParameter(STATE_SAVING_METHOD_PARAM_NAME);
        if (saveStateParam != null &&
            saveStateParam.equalsIgnoreCase(STATE_SAVING_METHOD_CLIENT)) {
            savingStateInClient = Boolean.TRUE;
        }
        return savingStateInClient.booleanValue();
}

Note that this is just the proposal in broad lines, not necessarily the
actual way to implement it.

1405 can be implemented in isolation, but IFF 1406 is also done, then this
may have some effect on 1405.

Kind regards,
Arjan Tijms