Developing Web 2.0 applications
with JavaServerFaces
and Dreamweaver
>> Just Became Easier
Documentation
Search
  1. Introduction
  2. Getting Started
  3. Developing Web Sites
  4. Using Components
  5. Internationalization
  6. Code View Support
  7. Design View Support
  8. Keyboard Shortcuts
  9. Tag Object Toolbars
  10. JSF Server Behaviors
  11. Property Inspectors
  12. JSF Tag Reference
JSF HTML Tag Library
  h:body
  h:button
  h:column
Selected h:commandButton
  h:commandLink
  h:dataTable
  h:form
  h:graphicImage
  h:head
  h:inputHidden
  h:inputSecret
  h:inputText
  h:inputTextarea
  h:link
  h:message
  h:messages
  h:outputFormat
  h:outputLabel
  h:outputLink
  h:outputScript
  h:outputStylesheet
  h:outputText
  h:panelGrid
  h:panelGroup
  h:selectBooleanCheckbox
  h:selectManyCheckbox
  h:selectManyListbox
  h:selectManyMenu
  h:selectOneListbox
  h:selectOneMenu
  h:selectOneRadio
If you like this documentation, please take a look at my book:

12. JSF HTML Tag Reference

Documentation > JSF > JSF Tag Reference > JSF HTML Tag Library > h:commandButton

h:commandButton

The commandButton tag renders an HTML submit button that can be associated with a backing bean or ActionListener class for event handling purposes. The display value of the button can also be obtained from a message bundle to support internationalization (I18N).

JSF Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html">
<h:head/>
<body>
<h:form>
	<h:commandButton value="#{messages.checkoutLabel}" 
	                 action="#{shoppingCartBean.checkout}" />
</h:form>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.

com/mycompany/messages.properties

checkoutLabel=Checkout

/WEB-INF/faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
	version="2.0">
	<application>
		<resource-bundle>
			<base-name>com.mycompany.messages</base-name>
			<var>messages</var>
		</resource-bundle>
	</application>
</faces-config>

Rendered Output

Rendered h:commandButton tag

Tag Attributes

accesskey Text
 
The accesskey attribute is a standard HTML attribute that sets the access key that transfers focus to this element when pressed.
action Text
 
The action attribute accepts a method-binding expression for a backing bean action method to invoke when this component is activated by the user. An action method must be a public method with no parameters that returns a String. The returned string represents the logical outcome of the action (eg. "success", "failure", etc. ) and is used by the JavaServer Faces MVC framework to determine which view to display next.
actionListener Text
 
The actionListener attribute accepts a method-binding expression for a backing bean action listener method that will be notified when this component is activated by the user. An action listener method must be a public method with an ActionEvent parameter and a void return type.
alt Text
 
The alt attribute is a standard HTML attribute that sets the alternate textual description rendered by this component.
binding Expression
 
The value-binding expression linking this component tag to a backing bean property.
dir Enumerated
 
The dir attribute is a standard HTML attribute that overrides the default text directionality for this component. The values accepted for this component are "LTR" (left-to-right) and "RTL" (right-to-left).

This attribute accepts the following values:

  • LTR
  • RTL
disabled Boolean
 
The disabled attribute is a boolean flag that when set to true indicates that this component should not receive focus or be included in a form submit.
id Text
 
The unique identifier value for this component. The value must be unique within the closest naming container.
image Text
 
The image attribute accepts an absolute or relative URL for the image to be displayed for this component instead of the standard HTML button widget. When set, this attribute changes the type of the resulting input element to "image".
immediate Boolean
 
The immediate attribute is a boolean flag indicating that component events should be sent to registered event listeners immediately rather than after the validation phase of the JSF request processing lifecycle. The immediate flag allows you bypass JSF validation for a particular component.
label Text
 
A localized user presentable name for this component.
lang Text
 
The lang attribute is a standard HTML attribute that sets the code describing the language to be used in the markup generated by this component.
onblur Text
 
The onblur attribute sets the JavaScript code to execute when this element loses focus.
onchange Text
 
The onchange attribute sets the JavaScript code to execute when this element loses focus and its value changes after gaining focus.
onclick Text
 
The onclick attribute sets the JavaScript code to execute when the mouse pointer is clicked over this element.
ondblclick Text
 
The ondblclick attribute sets the JavaScript code to execute when the mouse pointer is double-clicked over this element.
onfocus Text
 
The onfocus attribute sets the JavaScript code to execute when the element receives focus.
onkeydown Text
 
The onkeydown attribute sets the JavaScript code to execute when a key is pressed down over this element.
onkeypress Text
 
The onkeypress attribute sets the JavaScript code to execute when a key is pressed and released over this element.
onkeyup Text
 
The onkeyup attribute sets the JavaScript code to execute when a key is released over this element.
onmousedown Text
 
The onmousedown attribute sets the JavaScript code to execute when the mouse pointer is pressed down over this element.
onmousemove Text
 
The onmousemove attribute sets the JavaScript code to execute when the mouse pointer is moved within this element.
onmouseout Text
 
The onmouseout attribute sets the JavaScript code to execute when the mouse pointer is moved away from this element.
onmouseover Text
 
The onmouseover attribute sets the JavaScript code to execute when the mouse pointer is moved onto this element.
onmouseup Text
 
The onmouseup attribute sets the JavaScript code to execute when the mouse button is released over this element.
onselect Text
 
The onselect attribute sets the JavaScript code to execute when the user selects the text contained by this element.
readonly Boolean
 
The readonly attribute is a boolean flag that when set to true prohibits changes to this element by the user. The element will continue to receive focus unless you set the disabled attribute to true.
rendered Boolean
 
A value-binding expression that evaluates to a Boolean condition indicating if this component should be rendered.
style Text
 
The style attribute sets the CSS style definition to be applied to this component when it is rendered.
styleClass Text
 
The styleClass attribute sets the CSS class to apply to this component when it is rendered.
tabindex Text
 
The tabindex attribute is a standard HTML attribute that sets the order in which this element receives focus when the user cycles through the elements using the TAB key. The value for this attribute must be an integer between 0 and 32767.
title Text
 
The title attribute is a standard HTML attribute that sets the tooltip text to display for the rendered component.
type Enumerated
 
The type attribute sets the type of button to create for this component. The valid values for this attribute are "submit" and "reset". The default value for this attribute is "submit".

This attribute accepts the following values:

  • reset
  • submit
value Text
 
The value attribute sets the display value for the button rendered by this component.