### 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.8. < a4j:commandButton >

### 6.8.1. Description

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.16. a4j : commandButton attributes

Attribute Name | Description
--- | ---
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
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 | boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only
alt | Alternate textual description of the element rendered by this component.
binding | 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
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 | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
disabled | If "true", disable this component on page.
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 element to set focus after request completed on client side
id | 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.
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.
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 | 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 | The client side script method to be called when the element loses the focus
onchange | The client side script method to be called when the element value is changed
onclick | The clientside 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 | The client side script method to be called when the element is double-clicked
onfocus | The client side script method to be called when the element gets the focus
onkeydown | The client side script method to be called when a key is pressed down over the element
onkeypress | The client side script method to be called when a key is pressed over the element and released
onkeyup | The client side script method to be called when a key is released
onmousedown | The client side script method to be called when a mouse button is pressed down over the element
onmousemove | The client side script method to be called when a pointer is moved within the element
onmouseout | The client side script method to be called when a pointer is moved away from the element
onmouseover | The client side script method to be called when a pointer is moved onto the element
onmouseup | 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
rendered | 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
similarityGroupingId | If there are any component requests with identical IDs then these requests will be grouped.
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
status | ID (in format of call UIComponent.findComponent()) of Request status component
style | CSS style(s) is/are to be applied when this component is rendered
styleClass | Corresponds to the HTML class attribute
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.
title | Advisory title information about markup elements generated for this component
type | This attribute specifies a type of control to create. The possible values are "submit", "reset", "image" and "button". The default value for this attribute is "submit"
value | The current value for this component

Table 6.17. Component identification parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.CommandButton
component-family | javax.faces.Command
component-class | org.ajax4jsf.component.html.HtmlAjaxCommandButton
renderer-type | org.ajax4jsf.components.AjaxCommandButtonRenderer

### 6.8.2. Creating on a page

The simplest tag usage example:

Example:

    ...

    <a4j:commandButton reRender="someData" action="#{bean.action1}" value="Link"/>

    ...

### 6.8.3. Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.component.html.HtmlAjaxCommandButton;

    ...

    HtmlAjaxCommandButton myButton = new HtmlAjaxCommandButton();

    ...

### 6.8.4. Key attributes and ways of usage

<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.

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.

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

## Note:

AJAX support is built in and it's not necessary to add nested <a4j:support> to the component.

The usage of the keyword `'this'` in JavaScript code in the "oncomplete" attribute depends on the location of <a4j:commandButton> . If the commandButton is situated outside the re-rendered region you can use keyword 'this' as in the following example:

    ...

    <h:form id="form">

      <a4j:commandButton id="cbutton" action="director.rollCamera" onclick="this.disabled=true" oncomplete="this.disabled=false" />

    </h:form>

    ...

Otherwise if the commandButton contained in re-rendered region the "oncomplete" attribute has a problem obtaining a reference of the commandButton object when using the keyword `'this'`. In this case you can use the "oncomplete" attribute as in the following example:

    ...

    <h:form id="form">

         <a4j:commandButton id="cbutton" action="director.rollCamera"

             onclick="this.disabled=true"

             oncomplete="document.getElementById('form:cbutton').disabled=false" />

    </h:form>

    ...

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 Core Ajax 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.)

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

### 6.8.5. Relevant resources links

On the component LiveDemo page you can see the example of <a4j:commandButton> usage and sources for the given example.

- Prev6.7. < a4j:repeat >
- Top of page
- Front page
- Next6.9. < a4j:actionparam >