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.5. a4j:commandLink 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 |
| 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 rendered. |
| charset | The character encoding of a resource designated by this hyperlink |
| reRender | Id['s] (in format of call UIComopnent.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 |
| id | Every component may have a unique id that is automatically created if omitted |
| dir | Alternate textual description of the element rendered by this component |
| 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 |
| 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 |
| style | CSS style(s) is/are to be applied when this component is rendered |
| 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 |
| onmouseover | HTML: a script expression; a pointer is moved onto |
| 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 |
| 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 |
| 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 |
| lang | Code describing the language used in the generated markup for this component |
| onclick | HTML: a script expression; a pointer button is clicked |
| status | ID (in format of call UIComopnent.findComponent()) of Request status component. |
| 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 |
| 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.). |
| 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 |
| data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via this.data |
| onfocus | JavaScript code |
| onmouseup | HTML: script expression; a pointer button is released |
| ignoreDupResponses | ignoreDupResponses |
| 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.6. 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, 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.
import org.ajax4jsf.ajax.html.HtmlAjaxCommandLink;
...
HtmlAjaxCommandLink myLink = new org.ajax4jsf.ajax.html.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.)