The <a4j:ajaxListener> component is the same one as "ActionListener" or "ValueChangeListener", but for an AJAX container.
Table 6.1. a4j:ajaxListener attributes
| Attribute Name | Description |
|---|---|
| type | Fully qualified Java class name of an AjaxListener to be created and registered. |
<a4j:region selfRendered="true" ajaxListener="#{bean.processAjax}" id="Region">
</a4j:region>
Every time when AJAX request triggered from "region" method "processAjax" of "bean" will be called.
The <a4j:keepAlive> component allows to keep a state of each bean between requests.
Some additional information about usage of components can be found here.
The <a4j:actionparam> component combines the functionality of both JSF components: <f:param> and <f:actionListener> .
Table 6.3. a4j:actionparam attributes
| Attribute Name | Description |
|---|---|
| noEscape | If set to true, the value will not enclosed within single quotes and there will be no escaping of characters. This allows the use of the value as JavaScript code for calculating value on the client-side. This doesn't work with non-AJAX components. |
| value | An initial value or a value binding |
| converter | ID of a converter to be used or a reference to a converter. |
| assignTo | EL expression for updatable bean property. This property will be updated if the parent command component performs an actionEvent. |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| name | A name of this parameter |
| id | Every component may have a unique id that is automatically created if omitted |
The <a4j:commandButton> component is very similar to the <h:commandButton> component, the only difference is that an AJAX form submit is generated on a click and it allows dynamic rerendering after a response comes back. It's not necessary to plug any support into the component, as AJAX support is already built in.
Table 6.4. a4j:commandButton attributes
| Attribute Name | Description |
|---|---|
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| title | Advisory title information about markup elements generated for this component |
| oncomplete | JavaScript code for call after request completed on client side |
| rendered | If "false", this component is not rendered |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| focus | id of element to set focus after request completed on client side |
| onchange | HTML: script expression; the element value was changed |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| id | Every component may have a unique id that is automatically created if omitted |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| styleClass | Corresponds to the HTML class attribute |
| accesskey | This attribute assigns an access key to an element. An access key is a single character from the document character set. Note: Authors should consider the input method of the expected reader when specifying an accesskey |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| onkeypress | HTML: a script expression; a key is pressed and released |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| ondblclick | HTML: a script expression; a pointer button is double-clicked |
| image | Absolute or relative URL of the image to be displayed for this button. If specified, this "input" element will be of type "image". Otherwise, it will be of the type specified by the "type" property with a label specified by the "value" property. |
| style | CSS style(s) is/are to be applied when this component is rendered |
| size | This attribute tells the user agent the initial width of the control. The width is given in pixels except when type attribute has the value "text" or "password". In that case, its value refers to the (integer) number of characters |
| onblur | HTML: script expression; the element lost the focus |
| onmouseover | HTML: a script expression; a pointer is moved onto |
| value | The current value for this component |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| onkeyup | HTML: a script expression; a key is released |
| timeout | Timeout ( in ms ) for request. |
| tabindex | This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. User agents should ignore leading zeros |
| lang | Code describing the language used in the generated markup for this component |
| type | submit|reset|image|button This attribute specifies a type of control to create. The default value for this attribute is "submit" |
| actionExpression | The action method binding expression. |
| disabled | When set for a form control, this boolean attribute disables the control for user input |
| onclick | HTML: a script expression; a pointer button is clicked |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| onmouseout | HTML: a script expression; a pointer is moved away |
| alt | Alternate textual description of the element rendered by this component. |
| onkeydown | HTML: a script expression; a key is pressed down |
| onmousedown | HTML: script expression; a pointer button is pressed down |
| requestDelay | Delay (in ms.) for send ajax request on JavaScript event. In conjunction with events queue can reduce number of requests on keyboard or mouse move events |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| onfocus | HTML: script expression; the element got the focus |
| onmouseup | HTML: script expression; a pointer button is released |
| ignoreDupResponses | If true, unfinished request will be aborted on new event. |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| onmousemove | HTML: a script expression; a pointer is moved within |
Table 6.5. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.CommandButton |
| component-family | javax.faces.Command |
| component-class | org.ajax4jsf.ajax.html.HtmlCommandButton |
| renderer-type | org.ajax4jsf.components.AjaxCommandButtonRenderer |
<a4j:commandButton> is used in the same way as <h:commandButton> , but with definition of the area that is updated after the response comes back from the server.
<a4j:commandButton reRender="someData" action="#{bean.action1}" value="Link"/>This definition of the component provides a link, a click on the link causes an AJAX form submit on the server, "action1" method performance, and rendering of the component with "someData" id after the response comes back from the server.
Example:
import org.ajax4jsf.ajax.html.HtmlAjaxCommandButton; ... HtmlAjaxCommandButton myButton = new HtmlAjaxCommandButton(); ...
The component <a4j:commandButton> placed on a page generates the following HTML code:
<input type="submit" onclick="A4J.AJAX.Submit(...request parameters);return false;" value="sort"/>
Hence, the utility method "A4J.AJAX.Submit" is called on a click, the method performs AJAX request as the <a4j:support> component
AJAX support is built in and it's not necessary to add nested <a4j:support> to the component.
Common JSF navigation could be performed after an AJAX submit and partial rendering, but Navigation Case must be defined as <redirect/> in order to avoid problems with some browsers.
As any Ajax4jsf component sending AJAX requests and processing server responses <a4j:commandButton> has all attributes described above (see <a4j:support> chapter) that provide the required behavior of requests sending (delay, limitation of submit area and rendering, and etc.)
The <a4j:commandLink> component is very similar to the <h:commandLink> component, the only difference is that an AJAX form submit is generated on a click and it allows dynamic rerendering after a response comes back. It's not necessary to plug any support into the component, as AJAX support is already built in.
Table 6.6. a4j:commandLink attributes
| Attribute Name | Description |
|---|---|
| focus | id of element to set focus after request completed on client side |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| id | Every component may have a unique id that is automatically created if omitted |
| rev | A reverse link from the anchor specified by this hyperlink to the current document. The value of this attribute is a space-separated list of link types |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| style | CSS style(s) is/are to be applied when this component is rendered |
| onmouseover | HTML: a script expression; a pointer is moved onto |
| onkeyup | HTML: a script expression; a key is released |
| tabindex | This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. User agents should ignore leading zeros |
| timeout | Timeout ( in ms ) for request. |
| lang | Code describing the language used in the generated markup for this component |
| actionExpression | The action method binding expression. |
| onmouseout | HTML: a script expression; a pointer is moved away |
| rel | The relationship from the current document to the anchor specified by this hyperlink. The value of this attribute is a space-separated list of link types |
| onmouseup | HTML: script expression; a pointer button is released |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| onmousemove | HTML: a script expression; a pointer is moved within |
| coords | This attribute specifies the position and shape on the screen. The number and order of values depends on the shape being defined. Possible combinations: * rect: left-x, top-y, right-x, bottom-y. * circle: center-x, center-y, radius. Note. When the radius value is percentage value, user agents should calculate the final radius value based on the associated object's width and height. The radius should be the smaller value of the two. * poly: x1, y1, x2, y2, ..., xN, yN. The first x and y coordinate pair and the last should be the same to close the polygon. When these coordinate values are not the same, user agents should infer an additional coordinate pair to close the polygon. Coordinates are relative to the top, left corner of the object. All values are lengths. All values are separated by commas |
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| title | Advisory title information about markup elements generated for this component |
| shape | default|rect|circle|poly [CI] This attribute specifies the shape of a region. Possible values: * default: Specifies the entire region. * rect: Define a rectangular region. * circle: Define a circular region. * poly: Define a polygonal region. |
| oncomplete | JavaScript code for call after request completed on client side |
| target | This attribute specifies the name of a frame where a document is to be opened. By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements |
| charset | The character encoding of a resource designated by this hyperlink |
| rendered | If "false", this component is not rendered |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| styleClass | Corresponds to the HTML class attribute |
| accesskey | This attribute assigns an access key to an element. An access key is a single character from the document character set. Note: Authors should consider the input method of the expected reader when specifying an accesskey |
| onkeypress | HTML: a script expression; a key is pressed and released |
| ondblclick | HTML: a script expression; a pointer button is double-clicked |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| onblur | JavaScript code. The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| value | The current value for this component |
| hreflang | Base language of a resource specified with the href attribute; hreflang may only be used with href |
| type | The content type of the resource designated by this hyperlink |
| onclick | HTML: a script expression; a pointer button is clicked |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| onkeydown | HTML: a script expression; a key is pressed down |
| onmousedown | HTML: script expression; a pointer button is pressed down |
| requestDelay | Delay (in ms.) for send ajax request on JavaScript event. In conjunction with events queue can reduce number of requests on keyboard or mouse move events |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| onfocus | JavaScript code. The onfocus event occurs when an element gets focus |
| ignoreDupResponses | If true, unfinished request will be aborted on new event. |
Table 6.7. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.CommandLink |
| component-family | javax.faces.Command |
| component-class | org.ajax4jsf.ajax.html.HtmlCommandLink |
| renderer-type | org.ajax4jsf.components.AjaxCommandLinkRenderer |
<a4j:commandLink> is used in the same way as <h:commandLink> , but with definition of the area that is updated after the response comes back from the server.
<a4j:commandLink reRender="someData" action="#{bean.action1}" value="Link"/>This definition of the component provides a link, and a click on the link causes an AJAX form submit on the server, "action1" method performance, and rendering of the component with "someData" id after the response comes back from the server.
Example:
import org.ajax4jsf.ajax.html.HtmlAjaxCommandLink; ... HtmlAjaxCommandLink myLink = new HtmlAjaxCommandLink(); ...
The component <a4j:commandLink> placed on a page generates the following HTML code:
<a href="#" onclick="A4J.AJAX.Submit(?"request parameters"); return <a href="#" onclick="A4J.AJAX.Submit(?"request parameters"); return false;"> <span style="color: black;">Link Value</span> </a>
Hence, the utility method "A4J.AJAX.Submit" is called on a click, the method performs AJAX request as the <a4j:support> component
AJAX support is built in and it's not necessary to add nested <a4j:support> to the component.
Common JSF navigation could be performed after AJAX submit and partial rendering, but Navigation Case must be defined as <redirect/> in order to avoid problems with some browsers.
As any Ajax4jsf component sending AJAX requests and processing server responses <a4j:commandLink> has all attributes described above (see <a4j:support> chapter) that provide the required behavior of requests sending (delay, limitation of submit area and rendering, etc.)
The <a4j:form> component is very similar to the same component from the JSF HTML library, the only slight difference is in generation of links inside and possibility of AJAX by-default submission.
Table 6.8. a4j:form attributes
| Attribute Name | Description |
|---|---|
| oncomplete | JavaScript code for call after request completed on client side |
| target | This attribute specifies the name of a frame where a document is to be opened. By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements |
| rendered | If "false", this component is not rendered |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| focus | id of element to set focus after request completed on client side |
| id | Every component may have a unique id that is automatically created if omitted |
| prependId | The flag indicating whether or not this form should prepend its id to its descendent id during the clientId generation process. If this flag is not set, the default value is true. |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| onreset | The onreset event occurs when a form is reset. It only applies to the FORM element |
| onsubmit | The onsubmit event occurs when a form is submitted. It only applies to the FORM element |
| accept | This attribute specifies a comma-separated list of content types that a server processing this form will handle correctly. User agents may use this information to filter out non-conforming files when prompting a user to select files to be sent to the server (cf. the INPUT element when type="file") |
| timeout | Timeout ( in ms ) for request. |
| enctype | This attribute specifies the content type used to submit the form to the server (when the value of method is "post"). The default value for this attribute is "application/x-www-form-urlencoded". The value "multipart/form-data" should be used in combination with the INPUT element, type="file" |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| ajaxSubmit | If true, it becomes possible to set AJAX submission way for any components inside . |
| requestDelay | Delay (in ms.) for send ajax request on JavaScript event. In conjunction with events queue can reduce number of requests on keyboard or mouse move events |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| acceptCharset | This attribute specifies the list of character encodings for input data that is accepted by the server processing this form. The value is a space- and/or comma-delimited list of charset values. The client must interpret this list as an exclusive-or list, i.e., the server is able to accept any single character encoding per entity received. The default value for this attribute is the reserved string "UNKNOWN". User agents may interpret this value as the character encoding that was used to transmit the document containing this FORM element |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| ignoreDupResponses | If true, unfinished request will be aborted on new event. |
Table 6.9. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.Form |
| component-family | javax.faces.Form |
| component-class | org.ajax4jsf.ajax.html.AjaxForm |
| renderer-type | org.ajax4jsf.FormRenderer |
Component definition on a page is similar to definition of the original component from JSF HTML library.
<a4j:form> <!--...Some content to be submitted.--> </a4j:form>
Example:
import org.ajax4jsf.ajax.html.AjaxForm; ... AjaxForm myForm = new AjaxForm(); ...
The difference with the original component is that all hidden fields required for command links are always rendered and it doesn't depend on links rendering on the initial page. It solves the problem with invalid links that weren't rendered on a page immediately, but after some AJAX request.
Beginning with release 1.0.5 additional attributes that make this form variant universal have appeared. With a new attribute definition as ajax= "true" , it becomes possible to set AJAX submission way for any components inside, i.e. not a page URL is used as an "action" attribute, but the javascript:A4J.AJAX.Submit(...) call. In this case, rendering is defined as reRender=list of Ids for the form element itself.
Example
<a4j:form id="helloForm" ajaxSubmit="true" reRender="table"> ... <t:dataTable id="table"... > ... </t:dataTable> ... <t:dataScroller for="table"... > ... </t:dataScroller> ... </a4j:form
This example shows that in order to make <t:dataScroller> submissions to be AJAX ones it's required only to place this <t:dataScroller> into <a4j:form> . In the other case it is necessary to redefine renders for its child links elements that are defined as <h:commandLink> and can't be made AJAX ones with using e.g. <a4j:support> .
The <a4j:htmlCommandLink> component is very similar to the same component from the JSF HTML library, the only slight difference is in links generation and problem solving that occurs when an original component is used.
Table 6.10. a4j:htmlCommandLink attributes
| Attribute Name | Description |
|---|---|
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| title | Advisory title information about markup elements generated for this component |
| shape | default|rect|circle|poly [CI] This attribute specifies the shape of a region. Possible values: * default: Specifies the entire region. * rect: Define a rectangular region. * circle: Define a circular region. * poly: Define a polygonal region. |
| target | This attribute specifies the name of a frame where a document is to be opened. By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements |
| rendered | If "false", this component is not rendered |
| charset | The character encoding of a resource designated by this hyperlink |
| id | Every component may have a unique id that is automatically created if omitted |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| rev | A reverse link from the anchor specified by this hyperlink to the current document. The value of this attribute is a space-separated list of link types |
| styleClass | Corresponds to the HTML class attribute |
| accesskey | This attribute assigns an access key to an element. An access key is a single character from the document character set. Note: Authors should consider the input method of the expected reader when specifying an accesskey |
| onkeypress | HTML: a script expression; a key is pressed and released |
| ondblclick | HTML: a script expression; a pointer button is double-clicked |
| style | CSS style(s) is/are to be applied when this component is rendered |
| onmouseover | HTML: a script expression; a pointer is moved onto |
| onblur | JavaScript code. The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus |
| onkeyup | HTML: a script expression; a key is released |
| value | The current value for this component |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| tabindex | This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. User agents should ignore leading zeros |
| hreflang | Base language of a resource specified with the href attribute; hreflang may only be used with href |
| lang | Code describing the language used in the generated markup for this component |
| type | The content type of the resource designated by this hyperlink |
| actionExpression | The action method binding expression. |
| disabled | When set for a form control, this boolean attribute disables the control for user input. |
| onclick | HTML: a script expression; a pointer button is clicked |
| onmouseout | HTML: a script expression; a pointer is moved away |
| onkeydown | HTML: a script expression; a key is pressed down |
| onmousedown | HTML: script expression; a pointer button is pressed down |
| rel | The relationship from the current document to the anchor specified by this hyperlink. The value of this attribute is a space-separated list of link types |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| onfocus | JavaScript code. The onfocus event occurs when an element gets focus |
| onmouseup | HTML: script expression; a pointer button is released |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| onmousemove | HTML: a script expression; a pointer is moved within |
| coords | This attribute specifies the position and shape on the screen. The number and order of values depends on the shape being defined. Possible combinations: * rect: left-x, top-y, right-x, bottom-y. * circle: center-x, center-y, radius. Note. When the radius value is percentage value, user agents should calculate the final radius value based on the associated object's width and height. The radius should be the smaller value of the two. * poly: x1, y1, x2, y2, ..., xN, yN. The first x and y coordinate pair and the last should be the same to close the polygon. When these coordinate values are not the same, user agents should infer an additional coordinate pair to close the polygon. Coordinates are relative to the top, left corner of the object. All values are lengths. All values are separated by commas |
Table 6.11. Component identification parameters
| Name | Value |
|---|---|
| component-type | javax.faces.HtmlCommandLink |
| component-family | javax.faces.Command |
| component-class | javax.faces.component.html.HtmlCommandLink |
| renderer-type | org.ajax4jsf.HtmlCommandLinkRenderer |
Component definition on a page is the same as for the original component from the JSF HTML library.
Example:
<a4j:htmlCommandLink value="value" action="action"/>
Example:
import javax.faces.component.html.HtmlCommandLink; ... HtmlCommandLink myForm = new HtmlCommandLink(); ...
The difference with the original component is that all hidden fields required for command links with the child <f:param> elements are always rendered and it doesn't depend on links rendering on the initial page. It solves the problem with invalid links that weren't rendered on a page immediately, but after some AJAX request.
Example:
<a4j:form>
...
<a4j:htmlComandLink action="action" value="link" rendered="#{bean.rendered}">
<f:param ...>
<a4j:htmlComandLink>
...
</a4j:form>
In this example <a4j:htmlCommandLink> works as standard <h:commandLink> , but here hidden fields required for correct functionality are rendered before the first downloading of a page, though it doesn't happen if its attribute isn't set to "false".
The <a4j:jsFunction> component allows to invoke the server side data and return it in a JSON format to use in a client JavaScript calls.
Table 6.12. a4j:jsFunction attributes
| Attribute Name | Description |
|---|---|
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| timeout | Response waiting time on a particular request. If a response is not received during this time, the request is aborted |
| actionExpression | The action method binding expression. |
| oncomplete | JavaScript code for call after request completed on client side |
| rendered | If "false", this component is not rendered |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| focus | id of element to set focus after request completed on client side |
| id | Every component may have a unique id that is automatically created if omitted |
| requestDelay | Delay (in ms.) for send ajax request on JavaScript event. In conjunction with events queue can reduce number of requests on keyboard or mouse move events |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| ignoreDupResponses | If "true", unfinished request will be aborted on new event |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| name | Name of generated JavaScript function definition |
Table 6.13. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.Function |
| component-family | org.ajax4jsf.components.AjaxFunction |
| component-class | org.ajax4jsf.ajax.html.HtmlAjaxFunction |
| renderer-type | org.ajax4jsf.components.AjaxFunctionRenderer |
Simple component definition example:
Example:
...
<head>
<script>
<!--There is some script named "myScript" that uses parameters which will be taken from server-->
</script>
</head>
<body>
...
<a4j:jsFunction data="#{bean.someProperty}" name="callScript" oncomplete="myScript(data.subProperty1, data.subProperty2)"/>
...
The script "myScript" will be called after bean.someProperty data will be returned from server(e.g. It'll be object with two subproperties).
Example:
import org.ajax4jsf.ajax.html.HtmlAjaxFunction; ... HtmlAjaxFunction myFunction = new HtmlAjaxFunction(); ...
As the component uses Ajax request to get data from server - it has all common Ajax Action attributes. So, action and actionListener can be invoked, and reRendering some parts of the page fired after calling function.
When using the <a4j:jsFunction> it's possible to initiate the AJAX request from the JavaScript and perform partial update of a page and/or invoke the JavaScript function with data returned by AJAX response.
...
<body onload="callScript()">
...
<h:form>
...
<a4j:jsFunction name="callScript" data="#{bean.someProperty1 }
"reRender="someComponent" oncomplete="myScript(data.subProperty1, data.subProperty2)">
<a4j:actionparam name="param_name" assignTo="#{bean.someProperty2}">
</a4j:actionparam>
</a4j:jsFunction>
...
</h:form>
...
</body>
...The <a4j:jsFunction> allows to use <a4j:actionparam> or pure <f:param> for passing any number of parameters of the JavaScript function into AJAX request. <a4j:jsFunction> is similar to <a4j:commandButton> , but it could be activated from the JavaScript code. It allows to invoke some server side functionality and use the returned data in the JavaScript function invoked from "oncomplete" attribute. So it's possible to use <a4j:jsFunction> instead of <a4j:commandButton> . You can put it anywhere, just don't forget to use <h:form> … </h:form> around it.
To see how <a4j:jsFunction> works on practice, look at a4j-jsFunction example from here.
The <a4j:include> component is used for page areas update after an AJAX request according to the faces-config Navigation Rules and for implementation of wizard-like parts work in AJAX mode.
Table 6.14. a4j:include attributes
| Attribute Name | Description |
|---|---|
| layout | HTML layout for generated markup. Possible values: "block" for generating an HTML <div> element, "inline" for generating an HTML <span> element, and "none" for generating no HTML element. There is a minor exception for the "none" case where a child element has the property "rendered" set to "false". In this case, we create an empty <span> element with same ID as the child element to use as a placeholder for later processing. |
| lang | Code describing the language used in the generated markup for this component |
| title | Advisory title information about markup elements generated for this component |
| ajaxRendered | Defines, whether the content of this component must be (or not) included in AJAX response created by parent AJAX Container, even if it is not forced by reRender list of ajax action. Ignored if component marked to output by Ajax action. default false |
| rendered | If "false", this component is not rendered |
| id | Every component may have a unique id that is automatically created if omitted |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| styleClass | Corresponds to the HTML class attribute |
| keepTransient | Flag for mark all child components to non-transient. If true, all children components will be set to non-transient state and keep in saved components tree. For output in self-renderer region all content ( By default, all content in <f:verbatim> tags and non-jsf elements in facelets, marked as transient - since, self-rendered ajax regions don't plain output for ajax processing ). |
| style | CSS style(s) is/are to be applied when this component is rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| viewId | viewId for included page. |
Table 6.15. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.Include |
| component-family | org.ajax4jsf.ajax.Output |
| component-class | org.ajax4jsf.ajax.html.Include |
| renderer-type | org.ajax4jsf.AjaxIncludeRenderer |
To use the component, it's necessary to place the following strings on a page:
Example:
<h:panelGroup id="wizard"> <a4j:include viewId="/pages/include/first.xhtml" /> </h:panelGroup>
For navigation inside a page defined in viewId any components responsible for AJAX requests to the server generation are used.
For example, the following component on the page "/pages/include/first.xhtml"
Example:
... <a4j:commandButton action="next" reRender="wizard"/> ...
And in faces-config it's defined:
Example:
<navigation-rule> <from-view-id>/pages/include/first.xhtml</from-view-id> <navigation-case> <from-outcome>next</from-outcome> <to-view-id>/pages/include/second.xhtml</to-view-id> </navigation-case> </navigation-rule>
In this case after a click on a button defined inside "first.xhtml" view, navigation is performed after an AJAX request (the same as standard JSF one) only inside this view.
<a4j:outputPanel ajaxRendered="true"> <a4j:include viewId="/pages/include/first.xhtml"/> </a4j:outputPanel>
If <a4j:include> is defined this way, any AJAX request returning outcome inside generates navigation with this <a4j:include> .
Ajax Action for navigation implementation inside view must be placed inside <a4j:include> pages. Navigation defined by these pages is applied to the <a4j:include> element current for them.
As in the general case for Ajax Action component, if the <a4j:action> component inside <a4j:include> returns outcome defined as <redirect/>, AJAX submit is performed with navigation of the whole page and not only of the current view.
Some additional information can be found on the Ajax4Jsf Users Forum.
The <a4j:loadBundle> component is similar to the same component from the JSF Core library. The component loads a resource bundle localized for the Locale of the current view and exposes it (as a Map) in the request attributes of the current request.
Table 6.16. a4j:loadBundle attributes
| Attribute Name | Description |
|---|---|
| var | Name of a request scope attribute under which the resource bundle will be exposed as a Map. |
| basename | Base name of the resource bundle to be loaded. |
| rendered | If "false", this component is not rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| id | Every component may have a unique id that is automatically created if omitted |
Inserts script links to the head element. Render the value of the component as the value of the "src" attribute, after passing it to the getResourceURL() method of the ViewHandler for this application, and passing the result through the encodeResourceURL() method of the ExternalContext.
Table 6.17. a4j:loadScript attributes
| Attribute Name | Description |
|---|---|
| src | name of JavaScript resource to load. |
| rendered | If "false", this component is not rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| id | Every component may have a unique id that is automatically created if omitted |
Table 6.18. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.LoadScript |
| component-family | org.ajax4jsf.LoadScript |
| component-class | org.ajax4jsf.ajax.html.HtmlLoadScript |
| renderer-type | org.ajax4jsf.LoadScriptRenderer |
Simple Component definition on a page:
Example:
<a4j:loadScript src="scripts/someScript.js"/>
Example:
import org.ajax4jsf.ajax.html.HtmlLoadScript; ... HtmlLoadScript myScript = new HtmlLoadScript(); ...
As it was mentioned before this componment returns its value passing it to the getResourceUR() method of the ViewHandler for this application, and passing the result through the encodeResourceURL() method of the ExternalContext.
It means that the Context will be inserts automatically to the link. And calls like resource:// will be properly handled.
Except this - you may be free to put your script links right from the child page while using facelets templates .
Inserts stylesheet links to the head element. Render the value of the component as the value of the "src" attribute, after passing it to the getResourceURL() method of the ViewHandler for this application, and passing the result through the encodeResourceURL() method of the ExternalContext.
Table 6.19. a4j:loadStyle attributes
| Attribute Name | Description |
|---|---|
| src | name of JavaScript resource to load. |
| rendered | If "false", this component is not rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| id | Every component may have a unique id that is automatically created if omitted |
Table 6.20. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.LoadStyle |
| component-family | org.ajax4jsf.LoadStyle |
| component-class | org.ajax4jsf.ajax.html.HtmlLoadStyle |
| renderer-type | org.ajax4jsf.LoadStyleRenderer |
Simple Component definition on a page:
Example:
<a4j:loadStyle src="styles/style.css"/>
Example:
import org.ajax4jsf.ajax.html.HtmlLoadStyle; ... HtmlLoadScript myStyle = new HtmlLoadStyle(); ...
As it was mentioned before this componment returns its value passing it to the getResourceUR() method of the ViewHandler for this application, and passing the result via the encodeResourceURL() method of the ExternalContext.
It means that the Context will be inserts automatically to the link. And calls like resource:// will be properly handled.
Except this - you may be free to put your stylesheet links right from the child page while using facelets templates .
The <a4j:log > component generates JavaScript for opening of the window with client-side debug information on an AJAX request.
Table 6.21. a4j:log attributes
| Attribute Name | Description |
|---|---|
| level | log level, possible values : FATAL,ERROR,WARN,INFO,DEBUG,ALL. Component set level 'ALL' by default. |
| width | width of pop-up. |
| popup | Render log as popup-window or as div element in page |
| height | height of pop-up |
| hotkey | Keyboard key for activate ( in combination with CTRL+SHIFT ) log window. |
| rendered | If "false", this component is not rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| name | name of pop-up window |
| id | Every component may have a unique id that is automatically created if omitted |
Table 6.22. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.Log |
| component-family | org.ajax4jsf.ajax.Log |
| component-class | org.ajax4jsf.ajax.html.AjaxLog |
| renderer-type | org.ajax4jsf.LogRenderer |
To use the component, it's necessary to place the following string on a page:
<a4j:log/>
Then, in order to open a log window, press "CTRL+SHIFT+L" on a page with the component.
Example:
import org.ajax4jsf.ajax.html.AjaxLog; ... AjaxLog myLog = new AjaxLog(); ...
Usage of the appropriate component attributes could change a representation level of debug information as well as the hot key for a window opening.
The hot key could be changed with the "hotkey" attribute, where it's necessary to define one letter that together with "CTRL+SHIFT" opens a window.
The "level" attribute with several possible values (FATAL, ERROR, WARN, INFO, ALL) could change a logging level.
The log could be generated not only in a new window, but also on the current page in a separate <div> , this is also controlled with the "popup" attribute on the component.
Example:
<a4j:log level="ALL" popup="false" width="400" height="200"/>
The component defined this way is decoded on a page as <div> inside a page, where all the information beginning with informational message is generated.
<a4j:log> is getting renewed automatically after execution of ajax requests. Don't renew <a4j:log> by using reRender!
The <a4j:mediaOutput> component implements one of the basic features specified in the framework. The component is a facility for generating images, video, sounds and other binary resources defined by a user on-the-fly.
Table 6.23. a4j:mediaOutput attributes
| Attribute Name | Description |
|---|---|
| declare | declare but don't instantiate flag |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| id | Every component may have a unique id that is automatically created if omitted |
| rev | A reverse link from the anchor specified by this hyperlink to the current document. The value of this attribute is a space-separated list of link types |
| mimeType | Geterated content mime-type for append to response header ( 'image/jpeg' etc ) |
| style | CSS style(s) is/are to be applied when this component is rendered |
| onmouseover | HTML: a script expression; a pointer is moved onto |
| onkeyup | HTML: a script expression; a key is released |
| tabindex | This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. User agents should ignore leading zeros |
| archive | space-separated list of URIs |
| converter | ID of a converter to be used or a reference to a converter. |
| lang | Code describing the language used in the generated markup for this component |
| createContent | Method call expression to send generated resource to OutputStream. It must have two parameter with a type of java.io.OutputStream and java.lang.Object ( deserialized value of data attribute ) |
| onmouseout | HTML: a script expression; a pointer is moved away |
| element | Name of html element for resource link - may be <a> <img> <object> <applet> <script> or <link> |
| rel | The relationship from the current document to the anchor specified by this hyperlink. The value of this attribute is a space-separated list of link types |
| onmouseup | HTML: script expression; a pointer button is released |
| cacheable | If "true", the resource is cached (on the server and the client sides). |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| expires | The attribute allows to manage caching and defines the period after which a resource is reloaded. |
| onmousemove | HTML: a script expression; a pointer is moved within |
| coords | This attribute specifies the position and shape on the screen. The number and order of values depends on the shape being defined. Possible combinations: * rect: left-x, top-y, right-x, bottom-y. * circle: center-x, center-y, radius. Note. When the radius value is percentage value, user agents should calculate the final radius value based on the associated object's width and height. The radius should be the smaller value of the two. * poly: x1, y1, x2, y2, ..., xN, yN. The first x and y coordinate pair and the last should be the same to close the polygon. When these coordinate values are not the same, user agents should infer an additional coordinate pair to close the polygon. Coordinates are relative to the top, left corner of the object. All values are lengths. All values are separated by commas |
| title | Advisory title information about markup elements generated for this component |
| shape | default|rect|circle|poly [CI] This attribute specifies the shape of a region. Possible values: * default: Specifies the entire region. * rect: Define a rectangular region. * circle: Define a circular region. * poly: Define a polygonal region. |
| target | This attribute specifies the name of a frame where a document is to be opened. By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements |
| session | If "true", a session for an object generation is restored. |
| charset | The character encoding of a resource designated by this hyperlink |
| rendered | If "false", this component is not rendered |
| codetype | content type for code |
| classid | identifies an implementation |
| styleClass | Corresponds to the HTML class attribute |
| accesskey | This attribute assigns an access key to an element. An access key is a single character from the document character set. Note: Authors should consider the input method of the expected reader when specifying an accesskey |
| onkeypress | HTML: a script expression; a key is pressed and released |
| ondblclick | HTML: a script expression; a pointer button is double-clicked |
| align | bottom|middle|top|left|right Deprecated. This attribute specifies the position of an IMG, OBJECT, or APPLET with respect to its context. The following values for align concern the object's position with respect to surrounding text: * bottom: means that the bottom of the object should be vertically aligned with the current baseline. This is the default value. * middle: means that the center of the object should be vertically aligned with the current baseline. * top: means that the top of the object should be vertically aligned with the top of the current text line |
| vspace | Deprecated. This attribute specifies the amount of white space to be inserted above and below an IMG, APPLET, or OBJECT. The default value is not specified, but is generally a small, non-zero length |
| lastModified | The attribute allows to manage caching. A browser can send request with the header "If-Modified-Since" for necessity of object reloading. If time of modification is earlier, then the framework doesn't call generation and return code 304. |
| usemap | use client-side image map |
| standby | message to show while loading |
| border | Deprecated. This attribute specifies the width of an IMG or OBJECT border, in pixels. The default value for this attribute depends on the user agent |
| onblur | JavaScript code. The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus |
| value | Data value calculated at render time and stored in URI (also as part of cache Key ), at generation time passed to send method. Can be used for update cache at change of generating conditions, and for creating beans as "Lightweight" pattern components (request scope). IMPORTANT: Since serialized data stored in URI, avoid using big objects. |
| hreflang | Base language of a resource specified with the href attribute; hreflang may only be used with href |
| codebase | base URI for classid, data, archive |
| type | The content type of the resource designated by this hyperlink |
| uriAttribute | Name of attribute for resource-link attribute ( 'href' for <a>, 'src' for <img> or <script>, etc |
| onclick | HTML: a script expression; a pointer button is clicked |
| ismap | use server-side image map |
| onkeydown | HTML: a script expression; a key is pressed down |
| onmousedown | HTML: script expression; a pointer button is pressed down |
| hspace | Deprecated. This attribute specifies the amount of white space to be inserted to the left and right of an IMG, APPLET, or OBJECT. The default value is not specified, but is generally a small, non-zero length |
| onfocus | JavaScript code. The onfocus event occurs when an element gets focus |
Table 6.24. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.MediaOutput |
| component-family | org.ajax4jsf.Resource |
| component-class | org.ajax4jsf.ajax.html.MediaOutput |
| renderer-type | org.ajax4jsf.MediaOutputRenderer |
To use the component it's necessary to define it on a page and set Java methods for data keeping and data transmission to output stream.
Component definition on a page for graphical data output
Example:
...
<a4j:mediaOutput element="img" cacheable="false" session="true"
createContent="#{paintBean.paint}" value="#{paintData}"
mimeType="image/jpeg"/>
...
Here is the content of paintData that is a bean containing output data
Example:
package demo;
public class PaintData implements Serializable{
private static final long serialVersionUID = 1L;
Integer width=100;
Integer weight=50;
...
The Paint method of the paintBean class is a method transmitting graphical data into output stream.
Example:
public void paint(OutputStream out, Object data) throws IOException{
<!--...Some code that puts binary data to "out" Stream-->
}
Example:
import org.ajax4jsf.ajax.html.MediaOutput; ... MediaOutput myMedia = new MediaOutput (); ...
As it was shown in the example above there are two main components:
Hence, when using the component it's possible to output user data of any type on a page with AJAX requests.
The component is used for components grouping in the AJAX output area, which offers several additional output opportunities such as inserting of non-present in tree components, saving of transient elements after AJAX request and some others.
Table 6.25. a4j:outputPanel attributes
| Attribute Name | Description |
|---|---|
| onkeyup | HTML: a script expression; a key is released |
| layout | HTML layout for generated markup. Possible values: "block" for generating an HTML <div> element, "inline" for generating an HTML <span> element, and "none" for generating no HTML element. There is a minor exception for the "none" case where a child element has the property "rendered" set to "false". In this case, we create an empty <span> element with same ID as the child element to use as a placeholder for later processing. |
| lang | Code describing the language used in the generated markup for this component |
| title | Advisory title information about markup elements generated for this component |
| ajaxRendered | Defines, whether the content of this component must be (or not) included in AJAX response created by parent AJAX Container, even if it is not forced by reRender list of ajax action. Ignored if component marked to output by Ajax action. default false |
| onclick | HTML: a script expression; a pointer button is clicked |
| rendered | If "false", this component is not rendered |
| onmouseout | HTML: a script expression; a pointer is moved away |
| onkeydown | HTML: a script expression; a key is pressed down |
| onmousedown | HTML: script expression; a pointer button is pressed down |
| id | Every component may have a unique id that is automatically created if omitted |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| styleClass | Corresponds to the HTML class attribute |
| keepTransient | Flag for mark all child components to non-transient. If true, all children components will be set to non-transient state and keep in saved components tree. For output in self-renderer region all content ( By default, all content in <f:verbatim> tags and non-jsf elements in facelets, marked as transient - since, self-rendered ajax regions don't plain output for ajax processing ). |
| onkeypress | HTML: a script expression; a key is pressed and released |
| ondblclick | HTML: a script expression; a pointer button is double-clicked |
| onmouseup | HTML: script expression; a pointer button is released |
| style | CSS style(s) is/are to be applied when this component is rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| onmousemove | HTML: a script expression; a pointer is moved within |
| onmouseover | HTML: a script expression; a pointer is moved onto |
Table 6.26. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.OutputPanel |
| component-family | javax.faces.Panel |
| component-type | org.ajax4jsf.ajax.OutputPanel |
| component-class | org.ajax4jsf.ajax.html.HtmlAjaxOutputPanel |
| renderer-type | org.ajax4jsf.components.AjaxOutputPanelRenderer |
Here is the simplest way for a component creation on a page.
Example:
<a4j:outputPanel> <!--...Some Content Inside--> </a4j:outputPanel>
Example:
import org.ajax4jsf.ajax.html.HtmlAjaxOutputPanel; ... HtmlAjaxOutputPanel myPanel = new HtmlAjaxOutputPanel();
<a4j:outPanel> allows marking of a page area, which is updated on Ajax response. Anyway, <a4j:outputPanel> usage is optional, as in Ajax4jsf it's possible to indicate any existing component id on a component view in order to define updating areas. To speed up the performance, Ajax4jsf updates only a component tree. <a4j:outputPanel> usage is recommended for wrapping components that aren't rendered during the primary non-ajax response, as the components don't present in a component tree.
Example:
<a4j:support ... reRender="mypanel"/>
...
<a4j:outputPanel id="mypanel">
<h:panelGrid rendered="#{not empty foo.bar}">
...
</h:panelGrid>
</a4j:outputPanel>
In addition to the areas directly indicated in reRender attribute of Ajax components, <a4j:outputPanel> allows to update a part of a page basing on its own flag. The flag is defined by the ajaxRendered attribute. The flag is commonly used when a part of a page must be updated or can be updated on any response.
Example:
<a4j:outputPanel ajaxRendered="true"> <h:messages/> </a4j:outputPanel>
On default <a4j:outputPanel> is output as a pair of opening and closing html <span> tag, but with the help of the layout attribute this output way could be changed. There are three variants for this component value:
If layout="block" is chosen, the component is rendered as a pair of opening and closing <div> tag, to which it’s possible to apply any available style attributes available for block tags.
Layout="none" helps to avoid an unnecessary tag round a context that could or couldn't be rendered according to the defined "rendered" attribute conditions. If an inner context isn’t rendered, <a4j:outputPanel> is rendered as a <span> tag with the id equal to an id of a child component and "display:none" style. If a child component is rendered, <a4j:outputPanel> doesn't present at all in a final code.
Example:
<a4j:support .... reRender="mypanel"/>
...
<a4j:outputPanel layout="none">
<h:panelGrid id="mypanel" rendered="#{not empty foo.bar}">
...
</h:panelGrid>
</a4j:outputPanel>
As you see, the code is very similar to the one shown above, but "reRender " attribute refers directly to the updating panelGrid and not to the framing outputPanel, and it's more semantically correct.
<a4j:outPanel> should be used for non-JSF component part framing, which is to be updated on Ajax response, as Ajax4jsf specifies the list of updating areas as a list of an existing JSF component.
On default non-JSF context isn't saved in a component tree, but is rendered anew every time. To accelerate the processing speed and Ajax response input speed, Ajax4jsf saves non-JSF context in a component tree on default. This option could be canceled by keepTransient attribute that cancels transient flag forced setting for child components. This flag setting keeps the current value set by child components.
Note: In JSF 1.1 implementation and lower, where non-JSF context should be framed with the "f:verbatim" attribute, <a4j:outputPanel> doesn't improve this JSF implementation option in any way, so you still have to use this tag where it's necessary without Ajax4jsf usage.
Ajax4jsf allows setting Ajax responses rendering directly basing on component tree nodes without referring to the JSP (XHTML) page code. It could be defined by selfRendered attribute setting to "true" on <a4j:region> and could help considerably speed up a response output. However, if a transient flag is kept as it is, this rapid processing could cause missing of transient components that present on view and don’t come into a component tree. Hence, for any particular case you could choose a way for you application optimization: speed up processing or redundant memory for keeping tree part earlier defined a transient.
Some additional information about usage of component can be found here.
<a4j:page> is a deprecated component used for solving of incompatibility problems in early Ajax4jsf and MyFaces versions. The component encodes the full html page structure.
Table 6.27. a4j:page attributes
| Attribute Name | Description |
|---|---|
| namespace | Set html element default namespace |
| selfRendered | if "true", self-render subtree at InvokeApplication ( or Decode, if immediate property set to true ) phase |
| lang | Code describing the language used in the generated markup for this component |
| title | Advisory title information about markup elements generated for this component |
| onunload | JavaScript code to execute on a page unload. |
| rendered | If "false", this component is not rendered |
| contentType | Set custom mime content type to response |
| id | Every component may have a unique id that is automatically created if omitted |
| dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left) |
| styleClass | Corresponds to the HTML class attribute |
| immediate | Flag indicating that, if this component is activated by ajaxrequest, notifications should be delivered to interested listeners and actions immediately (that is, during Apply Request Values phase) rather than waiting until Invoke Application phase |
| onload | JavaScript code to execute on a page load. |
| pageTitle | String for output as a page title. |
| style | CSS style(s) is/are to be applied when this component is rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| ajaxListener | MethodBinding representing an action listener method that will be notified when this component is activated by the ajax Request and handle it. The expression must evaluate to a public method that takes an AjaxEvent parameter, with a return type of void |
| format | Page layout format ( html, xhtml, html-transitional, html-3.2 ) for encoding DOCTYPE, namespace and Content-Type definitions |
Table 6.28. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.components.Page |
| component-family | org.ajax4jsf.components.AjaxRegion. |
| component-class | org.ajax4jsf.components.Page |
| renderer-type | org.ajax4jsf.components.PageRenderer |
This component should be defined as a child component for <f:view>
<f:view> <a4j:page> <f:facet name="head"> <!--...Head Content here--> </f:facet> <!--...Page Content here--> </a4j:page> </f:view>
This structure is rendered as:
Example:
<HTML> <HEAD> <!--...Head Content here--> </HEAD> <body > <!--...Page Content Here--> </body> </HTML>
Example:
import org.ajax4jsf.components.Page; ... Page myPage = new Page(); ...
The component is mostly used to solve the following problem with MyFaces for erlier Ajax4gsf versions: in MyFaces <f:view> doesn't get control over the " RENDER_RESPONSE " phase, thus AJAX can't get control and make a response also. To avoid this problem it was necessary to use <a4j:page> on the page round the AJAX updatable area. In the last versions of both frameworks the problem is successfully fixed and no <a4j:page> usage is required.
The component is rendered as a full HTML page template (it was shown in the example). The " head " section is defined with the help of the corresponding facet with the name="head" and also there is an attribute with the same name for contentType definition.
All other component functionality is the same as of <a4j:region>. Its desctriprion could be found here.
The <a4j:poll> component allows periodical sending of AJAX requests to the server and is used for a page update according to a specified in milliseconds time interval.
Table 6.29. a4j:poll attributes
| Attribute Name | Description |
|---|---|
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| oncomplete | JavaScript code for call after request completed on client side |
| rendered | If "false", this component is not rendered |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| focus | id of element to set focus after request completed on client side |
| id | Every component may have a unique id that is automatically created if omitted |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| onsubmit | JavaScript code for call before submission of ajax event |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| timeout | Timeout (in ms) for request |
| actionExpression | The action method binding expression. |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| interval | Interval (in ms) for call poll requests. Default value 1000 (1 sec) |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| enabled | Enable/disable polling |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| ignoreDupResponses | If true, unfinished request will be aborted on new event. |
Table 6.30. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.components.Poll |
| component-family | org.ajax4jsf.components.AjaxPoll |
| component-class | org.ajax4jsf.components.AjaxPoll |
| renderer-type | org.ajax4jsf.components.AjaxPollRenderer |
To use this component it's necessary only to set an update interval.
Example:
<a4j:poll interval="1000" reRender="someDataTable" action="#{bean.action1}"/>
The <a4j:poll> component defined this way every second submits AJAX form onto the server, performs the corresponding action and renders a components with the "someDataTable" id after a response comes back.
Example:
import org.ajax4jsf.ajax.html.AjaxPoll; ... AjaxPoll myPoll = new AjaxPoll(); ...
The component decodes all necessary JavaScript for time count and on the expiry of some interval for calling of a Ajax4jsf utility method for Ajax request sending (A4J.AJAX.Submit (Some request parameters)).
The timer could be stopped or started in any time. The current state is controlled on the component with the "enabled" attribute:
<a4j:poll interval="1000" enabled="#{bean.boolProperty}"/>
As any Ajax4jsf Action component, <a4j:poll> has all described in the <a4j:support> chapter attributes to provide the necessary behavior of request sending (delay, limitation of a submit and render area, requests frequency, and etc.). For detailed information on these attributes see again the <a4j:support> component description.
The aditional information about component usage you can find here:Ajax4Jsf Users Forum.
The <a4j:push> periodically perform AJAX request to server, to simulate 'push' data.
Table 6.32. a4j:push attributes
| Attribute Name | Description |
|---|---|
| actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void |
| oncomplete | JavaScript code for call after request completed on client side |
| rendered | If "false", this component is not rendered |
| reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection |
| focus | id of element to set focus after request completed on client side |
| id | Every component may have a unique id that is automatically created if omitted |
| bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input |
| limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components |
| ajaxSingle | if "true", submits ONLY one field/link, instead of all form controls |
| eventProducer | MethodBinding pointing at method accepting an PushEventListener with return type void. User bean must register this listener and send EventObject to this listener on ready. |
| action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property |
| timeout | Timeout (in ms) for request |
| actionExpression | The action method binding expression. |
| status | ID (in format of call UIComponent.findComponent()) of Request status component |
| interval | Interval (in ms) for call push requests. Default value 1000 (1 sec) |
| eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.) |
| immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase |
| enabled | Enable/disable pushing |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| ignoreDupResponses | If true, unfinished request will be aborted on new event. |
Table 6.33. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.components.Push |
| component-family | org.ajax4jsf.components.AjaxPush |
| component-class | org.ajax4jsf.components.AjaxPush |
| renderer-type | org.ajax4jsf.components.AjaxPushRenderer |
<a4j:push reRender="msg" eventProducer="#{messageBean.addListener}" interval="3000"/>import org.ajax4jsf.ajax.html.AjaxPush; ... AjaxPush myPush = new AjaxPush(); ...
The main difference between <a4j:push> and <a4j:poll> components is that <a4j:push> makes request to minimal code only (not to JSF tree) in order to check the presence of messages in the queue. If the message exists the complete request will be performed. The component doesn't poll registered beans but registers EventListener which receives messages about events.
There are some attributes which allows to customize of the component behaviour:
'interval' - Interval (in ms) for call push requests. Default value 1000 (1 sec).
Code for registration of listener:
public void addListener(EventListener listener) {
synchronized (listener) {
if (this.listener != listener) {
this.listener = (PushEventListener) listener;
}
Component can get message using current code:
System.out.println("event occurs");
synchronized (listener) {
listener.onEvent(new EventObject(this));
}
Thus, component 'push' uses asynchronous model instead of polls.
The <a4j:region> component defines an area that is decoded on the server after AJAX submission.
Table 6.34. a4j:region attributes
| Attribute Name | Description |
|---|---|
| selfRendered | if "true", self-render subtree at InvokeApplication ( or Decode, if immediate property set to true ) phase |
| renderRegionOnly | Flag to disable rendering in AJAX responses content outside of active region. If this attribute set to "true" , no one of the components outside of region will be included to AJAX response. If set to "false", search for components to include in response will be performed on all tree. Default "true" |
| immediate | Flag indicating that, if this component is activated by ajaxrequest, notifications should be delivered to interested listeners and actions immediately (that is, during Apply Request Values phase) rather than waiting until Invoke Application phase |
| rendered | If "false", this component is not rendered |
| binding | The attribute takes a value-binding expression for a component property of a backing bean |
| ajaxListener | MethodBinding representing an action listener method that will be notified when this component is activated by the ajax Request and handle it. The expression must evaluate to a public method that takes an AjaxEvent parameter, with a return type of void |
| id | Every component may have a unique id that is automatically created if omitted |
Table 6.35. Component identification parameters
| Name | Value |
|---|---|
| component-type | org.ajax4jsf.ajax.AjaxRegion |
| component-family | org.ajax4jsf.components.AjaxRegion. |
| component-class | org.ajax4jsf.ajax.html.HtmlAjaxRegion |
| renderer-type | org.ajax4jsf.components.AjaxRegionRenderer |
Here is an example of the region decoding on a page.
<a4j:region> <!--..Some content that will be decoded on server after Ajax request.--> </a4j:region>