DefaultCommand DefaultCommand controls which command to initiate form submit with when enter key is pressed. Example below demonstrates 3 types of buttons; non-ajax, ajax and standard. Multiple defaultCommand in same form is supported with scope option.
  • btn1
  • btn2
  • btn3

<h:form id="form"> 
    <p:growl autoUpdate="true"/>

    <h:panelGrid columns="2" cellpadding="5">
        <h:outputLabel for="btnSelect" value="Default Button:" />
        <p:selectOneMenu id="btnSelect" value="#{defaultCommandView.btn}" onchange="$('#form').submit()">
            <f:selectItems value="#{defaultCommandView.buttons}" />
        </p:selectOneMenu>
    </h:panelGrid>

    <p:separator />

    <h:panelGrid columns="3" cellpadding="5">
        <h:outputLabel for="name" value="Name:" style="font-weight:bold"/>
        <p:inputText id="name" value="#{defaultCommandView.text}" />
        <h:outputText value="#{defaultCommandView.text}" id="display" />
    </h:panelGrid>

    <p:commandButton value="Button1" id="btn1" actionListener="#{defaultCommandView.btn1Submit}" ajax="false"/>
    <p:commandButton value="Button2" id="btn2" actionListener="#{defaultCommandView.btn2Submit}" />
    <h:commandButton value="Button3" id="btn3" actionListener="#{defaultCommandView.btn3Submit}" />

    <p:defaultCommand target="#{defaultCommandView.btn}" />
</h:form>
                
PrimeTek, Copyright © 2015
All rights reserved.
Running PrimeFaces-6.1-SNAPSHOT on Mojarra-2.2.8.