JSF Showcase
h:commandButton
HtmlCommandButton is a UICommand component that renders a styleable HTML<input>
element. The default type is submit
. The component must be a child of h:form in order to trigger the action or actionListener.
Navigation Usage
The component can be used to navigate between pages with the action attribute. By specifying a<redirect>
element in the navigation-rule
, it will utilize the POST/REDIRECT/GET pattern.
Source Code
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:form> <f:facet name="label"> <h:selectBooleanCheckbox value="#{commandModelBean.ajax}"> <f:ajax render="field" /> </h:selectBooleanCheckbox> </f:facet> <!-- Navigation based on outcome of navigation-case defined in navigation-rule.xml --> <h:commandButton action="toParam" value="#{i18n['to-param-page']} >"> <f:ajax disabled="#{!commandModelBean.ajax}" /> </h:commandButton> <h:outputText id="parameterValue" value="foo=#{facesContext.externalContext.requestParameterMap['foo']}" /> </h:form> </ui:composition>
<?xml version="1.0"?> <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.2" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> <navigation-rule> <from-view-id>/views/component.xhtml</from-view-id> <navigation-case> <from-outcome>toParam</from-outcome> <to-view-id>/views/component.xhtml</to-view-id> <redirect> <view-param> <name>componentPrefix</name> <value>#{showcaseModelBean.selectedComponent.prefix}</value> </view-param> <view-param> <name>componentName</name> <value>#{showcaseModelBean.selectedComponent.lowerCaseName}</value> </view-param> <view-param> <name>componentUseCase</name> <value>param</value> </view-param> </redirect> </navigation-case> </navigation-rule> </faces-config>
@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; } }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20