<apex: commandButton> Component in Visualforce PageThe <apex:commandButton> component is one of the most important components of Visualforce. It is a button rendered as an HTML input element with a type attribute set to submit, reset or image. The value of the HTML's type attribute depends on the <apex:commandButton> tag's specified values. When the user presses the button, the action defined by the controller executes. Then either the page navigates to a different page or refreshes the current page based on the returned PageReference's variable. The HTML pass-through attributes are also supported by this component using the "html-" prefix. This component must always be a child of the <apex:form> component. The <apex:commandButton> component has the following attributes: 1. accesskeyThe accesskey attribute is of type string that is used for specifying the shortcut key that puts the command button in focus. Syntax: 2. actionThe action attribute is of type ApexPages.Action is used to define the action method invoked by the AJAX request to the server. The page simply refreshes when an action is not specified. Syntax: 3. altThe alt attribute is of type String that is used for specifying the alternative text description of the command button. Syntax: 4. dirThe dir attribute is of type String that specifies the direction in which the generated HTML component should be read. LTR and RTL are the two possible values for this attribute. Syntax: 5. disabledThe disabled attribute is of type Boolean that specifies whether this component should be displayed in the disabled state or not. By default, its value is set to false. Syntax: 6. id The id attribute is of type string that allows this component to be referenced by other components on the page. Syntax: 7. image The image attribute is of type string that specifies the absolute or relative URL of the image that will be displayed as this button. If we specify this attribute, the generated HTML input element type is set to image. Syntax: 8. immediate The immediate attribute is of type Boolean. If its value is true, the action associated with the component will happen immediately. The function will not process the validation rules associated with the fields on the page. Syntax 9. lang The lang is of type string used to specify the base language used for the generated HTML output. The values can be "en" or "en-US" etc. Syntax: 10. onblur The onblur attribute is of type string used to invoke the JavaScript method when the onblur event occurs or simply focus moves off of the command button. Syntax: 11. onclick The onclick attribute is of type string used to invoke the JavaScript method when the onclick event occurs or simply when the user clicks the command button. Syntax: 12. oncomplete The oncomplete attribute is of type string that is used to invoke the JavaScript method when the result of an AJAX update request completes on the client Syntax: 13. ondblclick The ondblclick attribute is of type string used to invoke the JavaScript method when the ondblclick event occurs or simply when the command button is clicked twice. Syntax: 14. onfocus The onfocus attribute is of type string that is used to invoke the JavaScript method when the onfocus event occurs or simply focus on the command button. Syntax: 15. onkeydownThe onkeydown attribute is of type string that is used to invoke the JavaScript method when the onkeydown event occurs or simply when the user presses a keyboard key. Syntax: 16. onkeypressThe onkeypress attribute is of type string that is used to invoke the JavaScript method when the onkeypress event occurs or simply when the user holds down or presses a keyboard key. Syntax: 17. onkeyupThe onkeyup attribute is of type string that is used to invoke the JavaScript method when the onkeyup event occurs or simply when the user releases a keyboard key. Syntax: 18. onmousedownThe onmousedown attribute is of type string that is used to invoke the JavaScript method when the onmousedown event occurs or simply when the user presses the mouse button. Syntax: 19. onmousemoveThe onmousemove attribute is of type string that is used to invoke the JavaScript method when the onmousemove event occurs or simply when the user moves the mouse pointer. Syntax: 20. onmouseoutThe onmouseout attribute is of type string that is used to invoke the JavaScript method when the onmouseout event occurs or simply when the user moves the mouse pointer away from the command button. Syntax: 21. onmouseoverThe onmouseover attribute is of type string that is used to invoke the JavaScript method when the onmouseover event occurs or simply when the user moves the pointer over the command button. Syntax: 22. onmouseupThe onmouseup attribute is of type string that is used to invoke the JavaScript method when the onmouseup event occurs or simply when the user releases the mouse button. Syntax: 23. renderedThe rendered attribute is of type Boolean that is used for specifying whether this component is rendered on the page or not. By default, its value is set to true. Syntax: 24. reRenderThe reRender attribute is of type Object that is Id of one or more components which we need to redraw when the client receives the result of the action method. Its value can be a single Id, comma-separated Id, or collection of Ids. Syntax: 25. statusThe status attribute is of type string used to specify the ID of an associated component that displays the status of an AJAX update request. Syntax: 26. styleThe style attribute is of type string used to specify the CSS applied to it. Inline CSS is used as a value for this attribute. Syntax: 27. styleClassThe styleClass attribute is of type string used to specify the external CSS stylesheet applied to it to display the command button. Syntax: 28. tabindexThe tabindex attribute is of type string used for specifying the order in which this button is selected compared to other page components when the user presses the Tab key repeatedly. Syntax: 29. timeoutThe timeout attribute is of type integer that is used to specify the amount of time before an AJAX update request should time out. Syntax: 30. titleThe title attribute is of type string that is used to specify the text that will be displayed as a tooltip when the mouse hovers this component Syntax: 31. valueThe value attribute is of type string used to specify the text displayed on the commandButton as its label. Syntax: Let's take an example to understand how we can use the apex:commandButton component inside the VF page: ApexCommandButtonExample.vfp ApexCommandButtonController.apxc Output |