My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

miercuri, 4 martie 2015

JSF logical and physical views

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

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors