### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

### 6.1.7. < a4j:commandLink > available since 3.0.0

expand all

#### 6.1.7.1. Description

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.12. a4j : commandLink attributes

Attribute Name | Description
--- | ---
accesskey | HTML: 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
action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by you, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property
actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingle | Limits JSF tree processing (decoding, conversion, validation and model updating) only to a component that sends the request. Boolean
binding | JSF: The attribute takes a value-binding expression for a component property of a backing bean
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
charset | HTML: The character encoding of a resource designated by this hyperlink
coords | HTML: The attribute specifies shape and it position on the screen. Possible values: "rect: left-x, top-y, right-x, bottom-y", "circle: center-x, center-y, radius", "poly: x1, y1, x2, y2, ..., xN, yN". Notes: a) when giving the radius value in percents, user agents should calculate the final radius value in pixels based on the associated object's width and height; b) the radius value should be smaller than center-x and center-y values; c) for a polygon, the first and last coordinate pairs should have same x and y to close the shape (x1=xN; y1=yN) (when these coordinates are different, user agents should infer an additional pair to close a polygon). Coordinates are relative to the top left corner of an object. All values are lengths. All values are comma separated.
data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
dir | HTML: Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
disabled | HTML: Disables the component on page. Boolean.
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.)
focus | ID of an element to set focus after request is completed on client side
hreflang | HTML: Base language of a resource specified with the href attribute; hreflang may only be used with href
id | JSF: Every component may have a unique id that is automatically created if omitted
ignoreDupResponses | Attribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
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
lang | HTML: Code describing the language used in the generated markup for this component
limitToList | If "true", then of all AJAX-rendered on the page components only those will be updated, which ID's are passed to the "reRender" attribute of the describable component. "false"-the default value-means that all components with ajaxRendered="true" will be updated.
onbeforedomupdate | The client-side script method to be called before DOM is updated
onblur | DHTML: The client-side script method to be called when the element loses the focus either when pointing a device or tabbing navigation. The attribute may be used with the same elements as onfocus
onclick | DHTML: The client-side script method to be called when the element is clicked
oncomplete | The client-side script method to be called after the request is completed
ondblclick | DHTML: The client-side script method to be called when the element is double-clicked
onfocus | DHTML: The client-side script method to be called when the element gets the focus
onkeydown | DHTML: The client-side script method to be called when a key is pressed down over the element
onkeypress | DHTML: The client-side script method to be called when a key is pressed over the element and released
onkeyup | DHTML: The client-side script method to be called when a key is released
onmousedown | DHTML: The client-side script method to be called when a mouse button is pressed down over the element
onmousemove | DHTML: The client-side script method to be called when a pointer is moved within the element
onmouseout | DHTML: The client-side script method to be called when a pointer is moved away from the element
onmouseover | DHTML: The client-side script method to be called when a pointer is moved onto the element
onmouseup | DHTML: The client-side script method to be called when a mouse button is released
process | Id['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 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
rel | HTML: 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
rendered | JSF: If "false", this component is not rendered
requestDelay | Attribute defines the time (in ms.) that the request will be wait in the queue before it is ready to send. When the delay time is over, the request will be sent to the server or removed if the newest 'similar' request is in a queue already
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
rev | HTML: 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
shape | HTML: This attribute specifies the shape of a region. The possible values are "default", "rect", "circle" and "poly".
similarityGroupingId | If there are any component requests with identical IDs then these requests will be grouped.
status | ID (in format of call UIComponent.findComponent()) of Request status component
style | HTML: CSS style rules to be applied to the component
styleClass | JSF: Assigns one or more CSS class names to the component. Corresponds to the HTML "class" attribute.
tabindex | HTML: 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
target | HTML: 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
timeout | Timeout ( in ms ) for request.
title | HTML: Advisory title information about markup elements generated for this component
type | HTML: The content type of the resource designated by this hyperlink
value | JSF: The current value for this component

Table 6.13. Component identification parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.CommandLink
component-family | javax.faces.Command
component-class | org.ajax4jsf.component.html.HtmlAjaxCommandLink
renderer-type | org.ajax4jsf.components.AjaxCommandLinkRenderer

#### 6.1.7.2. Creating the Component with a Page Tag

To create the simplest variant of the component on a page use the following syntax:

Example:

    <a4j:commandLink value="Follow this link" reRender="some ID" action="#{bean.action}" />

The example above creates a link on a page clicking on which causes an Ajax form submit on the server, `"action"` method performance, and rendering the component with `"someData"` ID after response comes back.

#### 6.1.7.3. Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.component.html.HtmlAjaxCommandLink;

    ...

    HtmlAjaxCommandLink myLink = new HtmlAjaxCommandLink();

    ...

#### 6.1.7.4. Details of Usage

The <a4j:commandLink> component is used in the same way as JSF <h:commandLink> . The difference is that in case of <a4j:commandLink> the components to be updated should be specified. In this chapter we will use the code from RichFaces Greeter and change there <a4j:commandButton> to <a4j:commandLink> :

    ...

    <a4j:commandLink value="Get greeting" reRender="greeting" />

    ...

It's not necessary to add nested <a4j:support> as the <a4j:commandLink> has an Ajax support already built-in. As a result of our changes we will get a form with "Get greeting" link instead of the button:

Figure 6.3. The RicjFaces greeter with <a4j:commandLink>

The example above generates the following HTML code:

    <a href="#" onclick="A4J.AJAX.Submit(?"request parameters"); return false;"><span>Get greeting</span></a>

If you click on the generated anchor the utility method `A4J.AJAX.Submit()` will be fired.

## Note:

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 Core Ajax component that sends Ajax requests and processes server responses the <a4j:commandLink> has all attributes that provide the required behavior of requests (delay, limitation of submit area and rendering, etc.)

Information about the "process" attribute usage you can find "Decide what to process" guide section.

#### 6.1.7.5. Relevant resources links

Vizit CommandLink demo page at RichFaces live demo for examples of component usage and their sources.

Useful articles:

- How to use "window.confirm" JavaScript with <a4j:commandLink> "onclick" attribute in RichFaces cookbook at JBoss portal.

- Prev6.1.6. < a4j:commandButton > ...
- Top of page
- Front page
- Next6.1.8. < a4j:jsFunction > ...