AJAX - Validations

Validations are executed on the server side and page is updated with ajax.

New Person

Source

<h:form id="form">

    <p:panel id="panel" header="New Person">

        <p:messages id="msgs"/>

        <h:panelGrid columns="3">
            <h:outputLabel for="firstname" value="Firstname: *" />
            <p:inputText id="firstname" value="#{personBean.firstname}" required="true" label="Firstname">
                <f:validateLength minimum="2" />
            </p:inputText>
            <p:message for="firstname" display="icon"/>

            <h:outputLabel for="surname" value="Surname: *" />
            <p:inputText id="surname" value="#{personBean.surname}" label="Surname" required="true">
                <f:validateLength minimum="2" />
                <p:ajax update="msgSurname" event="keyup" />
            </p:inputText>
            <p:message for="surname" id="msgSurname" display="icon"/>

        </h:panelGrid>

        <p:commandButton id="btn" value="Save" update="panel" actionListener="#{personBean.savePerson}"/>
    </p:panel>

</h:form>