DefaultCommand - Basic

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.

Documentation

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

    <p:panelGrid columns="2" layout="flex" columnClasses="p-col-4, p-col-8" styleClass="ui-fluid">
        <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:outputLabel for="name" value="Name:" style="font-weight:bold"/>
        <p:inputText id="name" value="#{defaultCommandView.text}" />
    </p:panelGrid>

    <br/>

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

    <p:defaultCommand target="#{defaultCommandView.btn}" />
</h:form>

FREE THEMES

Built-in component themes created by the PrimeFaces Theme Designer.

nova-light Nova-Light
nova-dark Nova-Dark
nova-colored Nova-Colored
luna-blue Luna-Blue
luna-amber Luna-Amber
luna-green Luna-Green
luna-pink Luna-Pink
omega Omega

PREMIUM TEMPLATES

Create awesome applications in no time using the premium templates and impress your users.