- 

Available since OmniFaces 1.0

The <o:validateOrder> validates if the values of the given UIInput components as specified in the components attribute are in the order as specified by the type attribute which accepts the following values:

  • lt (default): from least to greatest, without duplicates.
  • lte: from least to greatest, allowing duplicates (equal values next to each other).
  • gt: from greatest to least, without duplicates.
  • gte: from greatest to least, allowing duplicates (equal values next to each other).

This validator has the additional requirement that the to-be-validated values must implement Comparable. This validator throws an IllegalArgumentException when one or more of the values do not implement it. Note that when this validator is placed before all of the components, then it will only compare the raw unconverted submitted string values, not the converted object values. If you need to compare by the converted object values, then you need to place this validator after all of the components.

The default message is

{0}: Please fill out the values of all those fields in order

For general usage instructions, refer ValidateMultipleFields documentation.

Demo

Please fill out the values of all those fields in order


Please enter a valid start and end date in yyyy-MM-dd format


Please choose a valid start and end date in all rows (PrimeFaces example)

#Start dateEnd date
#0
#1
#2

 

Demo source code
<h:form>
    <h3>Please fill out the values of all those fields in order</h3>
    <o:validateOrder id="order" components="foo bar baz" />

    <h:panelGrid columns="3">
        <o:outputLabel for="foo" value="Foo" />
        <h:inputText id="foo" />
        <h:message for="foo" />

        <o:outputLabel for="bar" value="Bar" />
        <h:inputText id="bar" />
        <h:message for="bar" />

        <o:outputLabel for="baz" value="Baz" />
        <h:inputText id="baz" />
        <h:message for="baz" />

        <h:panelGroup />
        <h:commandButton value="submit">
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
        <h:panelGroup>
            <h:message for="order" />
            <h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
        </h:panelGroup>
    </h:panelGrid>
</h:form>

<hr />

<h:form>
    <h3>Please enter a valid start and end date in yyyy-MM-dd format</h3>

    <h:panelGrid columns="3">
        <h:outputLabel for="startDate" value="Start date" />
        <h:inputText id="startDate" required="true" requiredMessage="Please enter start date" 
            converterMessage="Date must be in format yyyy-MM-dd">
            <f:convertDateTime pattern="yyyy-MM-dd" />
        </h:inputText>
        <h:panelGroup>
            <h:message for="startDate" />
        </h:panelGroup>
        
        <h:outputLabel for="endDate" value="End date" />
        <h:inputText id="endDate" required="true" requiredMessage="Please enter end date"  
            converterMessage="Date must be in format yyyy-MM-dd">
            <f:convertDateTime pattern="yyyy-MM-dd" />
        </h:inputText>
        <h:panelGroup>
            <h:message for="endDate" />
            <o:validateOrder id="order" type="lte" components="startDate endDate" 
                message="Start date may not be after end date" showMessageFor="startDate" />
        </h:panelGroup>

        <h:panelGroup />
        <h:commandButton value="submit">
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
        <h:panelGroup>
            <h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
        </h:panelGroup>
    </h:panelGrid>
</h:form>

<hr />

<h:form>
    <h3>Please choose a valid start and end date in all rows (PrimeFaces example)</h3>

    <p:messages id="messages" />

    <p:dataTable binding="#{table}" value="#{of:createArray(3)}">
        <p:column headerText="#">
            ##{table.rowIndex}
        </p:column>
        <p:column headerText="Start date">
            <p:datePicker id="startDate" pattern="yyyy-MM-dd" required="true" 
                requiredMessage="Please enter start date ##{table.rowIndex}" />
        </p:column>
        <p:column headerText="End date">
            <p:datePicker id="endDate" pattern="yyyy-MM-dd" required="true" 
                requiredMessage="Please enter end date ##{table.rowIndex}" />
            <o:validateOrder components="startDate endDate" 
                message="End date ##{table.rowIndex} must be after start date ##{table.rowIndex}" />
        </p:column>
    </p:dataTable>
    
    <p>
        <p:commandButton value="Submit" update="@form" />
        &#xA0;
        <h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
    </p>
</h:form>