OpenFaces library has a range of Ajax-powered features built-in in components themselves, and facilities for
introducing inter-component Ajax-based interaction using the appropriate attributes in various command components
(such as CommandButton, CommandLink, PopupMenu's items, etc.), and with a generic non-visual "Ajax" component that can
be attached to any other JSF component to reload other components when some particular event occurs. Actually, the
Ajax component has a wider purpose than just reloading components which makes it possible to perform dynamic page
updates to meet a wide range of scenarios that require Ajax page updates.
Here are the major features of the Ajax component:
- Reloading components - The main purpose of this component is to reload one or
more components with Ajax without reloading the whole page. Just specify the space-separated list of component
ids in the "render" attribute.
- Two ways of attaching to components - You can either embed
tag right into the component that initiates Ajax reload, or attach to a component using the "for" attribute.
- Standalone mode for programmatic usage - Declare standalone="true" attribute,
and it becomes possible to run Ajax component reload programmatically. This is especially useful for complex
scenarios with conditional reloads, or when the same Ajax component should be reused in different places.
- Submitting additional components - Specifying a space-separated component ids in
the "execute" attribute includes data from other components into the reload procedure.
This is useful when the reloaded data or server action depends on data in various page's components.
- Executing server action - Specifying the "listener" attribute allows executing
a server action before reloading the components.
- Avoiding frequent requests - Sends only one request in case of several events
during the short period of time specified with the "delay" attribute.
- Ajax request lifecycle events - Use "onajaxstart", "onajaxend", and "onerror" events
to implement additional logic that is bound to the ajax reloading process itself.
Another valuable facility is an AjaxSettings component that allows customizing various aspects of Ajax
functionality on a page:
- Customizing ajax progress message - It is possible to change the text, style and
image displayed in the Ajax progress message, or it is possible to fully redefine the progress message by
specifying its HTML source.
- Customizing session expiration message - Any Ajax action on an expired session
leads to showing a message where the user chooses either to reload the page or cancel the action. The
AjaxSettings component can be used to define the policy on handling session expiration: showing a message, or
silent page reload.
- Page-wide Ajax request lifecycle events - The AjaxSettings component allows
receiving notifications for tracking Ajax request state on a page level using the "onajaxstart", "onajaxend",
"onerror", and "onsessionexpired" events.