, and it is used as a web technique for transferring XML between a browser and a server dynamically without posting a web page to the server.
The "asynchronous" in AJAX implies that the processing of the web page continues while XMLHttpRequest is processed on the server and a response is returned to the browser client. AJAX has a lot of applications such as an autocompletion feature that updates a form with corresponding, existing information when an entry is made in one field; dynamic form validation; and periodic refreshing of page sections or areas, which doesn't require reloading the entire web page.
Ajax4JSF provides a component library that you can use to give a JSF page AJAX functionality across the entire page. It supports action and value change listeners and server-side validation and conversion facilities of the JSF framework. Ajax4JSF also supports managing static and dynamic resources, such as images and cascading style sheets (CSSs) and the Facelets framework. To use Ajax4JSF, you need to have these tools installed:
- JDK 1.41.6
- JSF 1.1 or 1.2
- A J2EE application server, such as WebSphere 5.16, WebLogic 8.19.0, or Oracle OC4J 10.1.3
- A browser that supports XMLHttpRequest, such as Internet Explorer 6 or later or Netscape Navigator 6 or later.
An event on the page invokes an AJAX request, and specified regions of the page are updated with the AJAX response.
Now take a closer look at the Ajax4JSF framework. The Ajax filter is registered in the web.xml file and distinguishes between a JSF request and an AJAX request. In a JSF request the complete JSF page is synchronized with the JSF component tree, while in an AJAX request only the AJAX region, specified by <a4j:region> is updated with the AJAX response.
AJAX action componentsAjaxCommandButton, AjaxCommandLink, and AjaxSupportare used to send an AJAX request from the browser to the server.
Ajax4JSF provides a component library to implement AJAX functionality in JSF. Some of the commonly used components are listed in Table 1.
Table 1. Ajax4JSF Components
||This component specifies an area that is decoded in an AJAX request; however, components out of the region may be updated. The region defined by f:view is the default region.
||renderRegionOnly If set to TRUEthe default valuethe region only is updated with the response.|
rendered If set to FALSE the component is not rendered.
binding Component binding.
ajaxListener Method binding that represents a public method that returns void and accepts an AjaxEvent.
||This component adds AJAX support to a JSF component and generates an AJAX request on a specified event.
||actionListener Specifies method binding for a public method that returns void and accepts an ActionEvent.|
action Specifies a method binding for a backing bean method that is invoked after the specified event and before components are re-rendered with the AJAX response.
reRender Specifies a comma-separated list of component IDs that are updated with the AJAX response.
requestDelay Specifies the delay in number of milliseconds (ms) before sending an AJAX request.
binding Component binding.
||This component sends periodical AJAX requests at a specified frequency (ms) and updates the page with the response.
||interval Specifies the interval in milliseconds (ms) after which an AJAX request is sentthe default value is 1000 ms (1 second).|
actionListener, action, oncomplete, reRender, binding Same as for <a4j:support>.
||This component provides a link that submits a form with AJAX.
||reRender Specifies component IDs that are updated with an AJAX response.|
actionListener, oncomplete, action, requestDelay, binding Same as for <a4j:support>.
||This component provides a command button for using AJAX to submit a form.
||reRender, actionListener, oncomplete, action, requestDelay, binding Same as for <a4j:commandLink>.|
||This component provides component grouping in the output area that is updated with an AJAX response. The page area specified by this component may be updated in addition to the components specified in the reRender attribute of a component that initiates an AJAX request.
||layout Specifies HTML layout for generated markup; a value of block generates a <div> element and a value of inline generates a <span> element.|
style Specifies a CSS.
ajaxRendered Specifies if the component is to be updated in addition to the components updated with reRender.
||This component generates multimedia output.
||mimeType The mime-type of the generated contentfor example, image/jpeg.|
||This component provides a form that submits with AJAX.
||reRender, oncomplete, requestDelay, binding|
||Generates a pop-up for client-side debug information when an AJAX request is sent.
||level-Log level Values may be FATAL, ERROR, WARN, INFO, DEBUG, or ALL.|
width Specifies the width of the pop-up.
height Specifies the height of the pop-up.