Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.1.6.  < a4j:commandButton > available since 3.0.0

The <a4j:commandButton> component is very similar to JSF <h:commandButton> , the only difference is that an Ajax form submit is generated on a click and it allows dynamic rerendering after a response comes back.


Table 6.11. a4j : commandButton attributes

Attribute Name Description
accesskeyHTML: 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
actionMethodBinding 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
actionListenerMethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingleLimits JSF tree processing (decoding, conversion, validation and model updating) only to a component that sends the request. Boolean
altHTML: Alternate textual description of the element rendered by this component.
binding JSF: The attribute takes a value-binding expression for a component property of a backing bean
bypassUpdatesIf "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
dirHTML: Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
disabledHTML: If "true", disable this component on page.
eventsQueueName 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.)
focusID of an element to set focus after request is completed on client side
id JSF: Every component may have a unique id that is automatically created if omitted
ignoreDupResponsesAttribute 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.
imageAbsolute 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.
immediateTrue 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
langHTML: Code describing the language used in the generated markup for this component
limitToListIf "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.
onbeforedomupdateThe 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
onchange DHTML: The client-side script method to be called when the element value is changed
onclick DHTML: The client-side script method to be called when the element is clicked
oncompleteThe 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
processId['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 JSF: If "false", this component is not rendered
requestDelayAttribute 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
reRenderId['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
similarityGroupingIdIf there are any component requests with identical IDs then these requests will be grouped.
sizeHTML: 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
statusID (in format of call UIComponent.findComponent()) of Request status component
styleHTML: 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.
tabindexHTML: 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
timeoutTimeout ( in ms ) for request.
titleHTML: Advisory title information about markup elements generated for this component
typeHTML: 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 JSF: The current value for this component

Table 6.12. Component identification parameters

NameValue
component-typeorg.ajax4jsf.CommandButton
component-familyjavax.faces.Command
component-classorg.ajax4jsf.component.html.HtmlAjaxCommandButton
renderer-typeorg.ajax4jsf.components.AjaxCommandButtonRenderer


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

Example:


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

The example above creates a button 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.

Example:

import org.ajax4jsf.component.html.HtmlAjaxCommandButton;

...
HtmlAjaxCommandButton myButton = new HtmlAjaxCommandButton();
...

The <a4j:commandButton> component is used in the same way as JSF <h:commandButton> . The difference is that in case of <a4j:commandButton> the components to be updated should be specified.

The example above generates the following HTML code:


<input type="submit" onclick="A4J.AJAX.Submit(request parameters);return false;" value="Button"/>

Сlicking the generated anchor fires the utility method A4J.AJAX.Submit() that perfroms Ajax request.

Note:

The <a4j:commandButton> already has Ajax support built-in and there is no need to add <a4j:support> .

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


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

Otherwise, if the <a4j:commandButton> is contained in a re-rendered region than the "oncomplete" attribute has a problem with obtaining a reference of the commandButton object when using the keyword 'this'. In this case 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 that sends Ajax requests and processes server responses the <a4j:commandButton> has all attributes that provide the required behavior of requests (delay, limitation of submit area and rendering, etc.)

Note:

When attaching a JavaScript API function to the <a4j:commandButton> with the help of the <rich:componentControl> do not use the "attachTo" attribute of the last one. The attribute adds event handlers using Event.observe but <a4j:commandButton> has no such event. The example below will not work:


<a4j:commandButton value="Show Current Selection" reRender="table" action="#{dataTableScrollerBean.takeSelection}" id="button">
      <rich:componentControl attachTo="button" for="panel" event="oncomplete" operation="show" />
</a4j:commandButton>

This one should work properly:


<a4j:commandButton value="Show Current Selection" reRender="table" action="#{dataTableScrollerBean.takeSelection}" id="button">
      <rich:componentControl for="panel" event="oncomplete" operation="show" />
</a4j:commandButton>

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

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