Button/Link
Data
Input
Miscellaneous
Multimedia
Output
Panel
Select
JSTL
Faces Core
Facelets
Extensions

alloy:commandButton

CommandButton is a UICommand component that renders a styleable HTML <button> element. The default type is submit. Since it extends HtmlCommandButton, it supports all the features of h:commandButton. The component must be a child of h:form in order to trigger the action or actionListener. In order to provide a Rich Internet Application (RIA) experience for the end-user, the following attributes are set by default:

Value Attribute Usage

Although the component's value attribute is read-only (can't be changed via form submission), it can be used to determine that an item has been selected by the user.
John Adams
Samuel Adams
Josiah Bartlett
Carter Braxton
Charles Carroll
Benjamin Franklin

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:alloy="http://liferay.com/faces/alloy"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<alloy:form>
<ui:repeat value="#{commandModelBean.customers}" var="customer">
<alloy:commandButton actionListener="#{commandBackingBean.selectionListener}" render="@form"
value="#{customer}">
<alloy:icon name="edit" />
</alloy:commandButton>
<alloy:outputText value=" #{customer.fullName}" />
<br />
</ui:repeat>
<alloy:outputText id="modelValue" value="#{commandModelBean.selectedCustomer.fullName}" />
</alloy:form>
</ui:composition>
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@ManagedBean
@ViewScoped
public class CommandModelBean implements Serializable {
// serialVersionUID
private static final long serialVersionUID = 332271404377673109L;
// Injections
@ManagedProperty(value = "#{customerService}")
private CustomerService customerService;
// Private Data Members
private boolean ajax;
private Customer selectedCustomer;
private List<Customer> customers;
public List<Customer> getCustomers() {
return customers;
}
public Customer getSelectedCustomer() {
return selectedCustomer;
}
public boolean isAjax() {
return ajax;
}
@PostConstruct
public void postConstruct() {
customers = customerService.getCustomers(0, 5);
}
public void setAjax(boolean ajax) {
this.ajax = ajax;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
public void setSelectedCustomer(Customer selectedCustomer) {
this.selectedCustomer = selectedCustomer;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@ManagedBean
@RequestScoped
public class CommandBackingBean {
private static final Logger logger = LoggerFactory.getLogger(CommandBackingBean.class);
// Injections
@ManagedProperty(value = "#{commandModelBean}")
private CommandModelBean commandModelBean;
public void actionListener(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
PhaseId phaseId = facesContext.getCurrentPhaseId();
logger.debug("actionListener: phaseId=[{0}]", phaseId.toString());
String phaseName = phaseId.toString();
FacesMessage facesMessage = new FacesMessage("The actionListener method was called during the " + phaseName +
" phase of the JSF lifecycle.");
facesContext.addMessage(null, facesMessage);
}
public void ajaxListener(AjaxBehaviorEvent ajaxBehaviorEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
PhaseId phaseId = facesContext.getCurrentPhaseId();
logger.debug("ajaxListener: phaseId=[{0}]", phaseId.toString());
String phaseName = phaseId.toString();
FacesMessage facesMessage = new FacesMessage("The ajaxListener method was called during the " + phaseName +
" phase of the JSF lifecycle.");
facesContext.addMessage(null, facesMessage);
}
public void attributeActionListener(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
PhaseId phaseId = facesContext.getCurrentPhaseId();
logger.debug("actionListener: phaseId=[{0}]", phaseId.toString());
String value = (String) actionEvent.getComponent().getAttributes().get("attribute");
String phaseName = phaseId.toString();
FacesMessage facesMessage = new FacesMessage("The actionListener method was called during the " + phaseName +
" phase of the JSF lifecycle.The attribute value is " + value);
facesContext.addMessage(null, facesMessage);
}
public void attributesActionListener(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
PhaseId phaseId = facesContext.getCurrentPhaseId();
logger.debug("actionListener: phaseId=[{0}]", phaseId.toString());
Map<String, Object> attributes = actionEvent.getComponent().getAttributes();
String value1 = (String) attributes.get("attribute1");
String value2 = (String) attributes.get("attribute2");
String phaseName = phaseId.toString();
FacesMessage facesMessage = new FacesMessage("The actionListener method was called during the " + phaseName +
" phase of the JSF lifecycle.The attributes value are " + value1 + " and " + value2);
facesContext.addMessage(null, facesMessage);
}
public void feedbackListener(ActionEvent actionEvent) {
String value = "";
List<UIComponent> children = actionEvent.getComponent().getChildren();
for (UIComponent uiComponent : children) {
if (uiComponent instanceof UIOutput) {
value = (String) ((UIOutput) uiComponent).getValue();
}
}
FacesContext facesContext = FacesContext.getCurrentInstance();
logger.debug("feedbackListener: You selected the '" + value + "' menu item.");
FacesMessage facesMessage = new FacesMessage("You selected the '" + value + "' menu item.");
facesContext.addMessage(null, facesMessage);
}
public Map<String, Object> getAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("attribute1", "value1");
attributes.put("attribute2", "value2");
return attributes;
}
public void parameterActionListener() {
FacesContext facesContext = FacesContext.getCurrentInstance();
PhaseId phaseId = facesContext.getCurrentPhaseId();
logger.debug("actionListener: phaseId=[{0}]", phaseId.toString());
Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
String value = requestParameterMap.get("parameter");
String phaseName = phaseId.toString();
FacesMessage facesMessage = new FacesMessage("The actionListener method was called during the " + phaseName +
" phase of the JSF lifecycle.The parameter value is " + value);
facesContext.addMessage(null, facesMessage);
}
public void selectionListener(ActionEvent actionEvent) {
UICommand uiCommand = (UICommand) actionEvent.getComponent();
Customer customer = (Customer) uiCommand.getValue();
commandModelBean.setSelectedCustomer(customer);
}
public void setCommandModelBean(CommandModelBean commandModelBean) {
this.commandModelBean = commandModelBean;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public class Customer implements Serializable {
// serialVersionUID
private static final long serialVersionUID = 6155011527137371447L;
// Private Data Members
private long customerId;
private Country country;
private Date dateOfBirth;
private String firstName;
private String lastName;
public Customer(long customerId, Country country, String firstName, String lastName, Date dateOfBirth) {
this.customerId = customerId;
this.country = country;
this.dateOfBirth = dateOfBirth;
this.firstName = firstName;
this.lastName = lastName;
}
public Country getCountry() {
return country;
}
public long getCustomerId() {
return customerId;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public String getFirstName() {
return firstName;
}
public String getFullName() {
return firstName + " " + lastName;
}
public String getLastName() {
return lastName;
}
public void setCountry(Country country) {
this.country = country;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Liferay Faces Alloy 4.1.1 + Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 4.0.0 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20