We know that
JSF can store a full or partial view state on server or on client with some
advantages and disadvantages. Further, you have to know that JSF differentiates
views in logical views (specific to the GET requests) and physical views (specific
to the POST requests). Each GET request generates a new logical view. By default,
JSF Mojarra (the reference implementation of JSF) manages 15 logical views, but
this number can be adjusted through the context parameter, com.sun.faces.numberOfLogicalViews,
as shown in the following code:
<context-param>
<param-name>com.sun.faces.numberOfLogicalViews</param-name>
<param-value>2</param-value>
</context-param>
You can
easily perform a test of this setting by starting the browser and opening an application
three times, in three different browser tabs. Afterwards, come back to the
first tab and try to submit the form. You will see a ViewExpiredException because
the first logical view was removed from the logical views map, as shown in the
following screenshot:
If you open
the application in one or two tabs, this error will not occur. There is another
story with the POST requests (non-AJAX), because, in this case, JSF (Mojarra
implementation) will store every single form in the session until the maximum
size is reached. A POST request creates a new physical view (except AJAX requests
which use the same physical view repeatedly) and JSF Mojarra can store 15 physical
views per logical view (Map<LogicalView, Map<PhysicalView, and ViewState>>).
Obviously, a physical view can contain multiple forms.
You can
control the number of physical views through the context parameter named com.sun.faces.numberOfViewsInSession.
For example, you can decrease its value to 4 as shown in the following code:
<context-param>
<param-name>com.sun.faces.numberOfViewsInSession</param-name>
<param-value>4</param-value>
</context-param>
This small
value allows you to perform a quick test. Open an application in the browser
and submit a form four times. Afterwards, press the browser's back button four
times, to return to the first form and try to submit it again. You will see an
exception, because this physical view was removed from the physical view's map.
This will not happen if you submit the form less than four times.
Note In
case you need more than 15 logical/physical views, then you can increase their
number or choose to save the state on the client. Saving the state on the
client is recommended since it will totally eliminate
this problem.
In case of
navigation between pages, JSF doesn't store anything in the session for the GET
requests, but will save the state of forms for the POST requests.
You also may
be interested in:
JSF saving the view state
Niciun comentariu :
Trimiteți un comentariu