The Java EE 6 Tutorial

Using LongRangeValidator

The following example shows how to use the validateLongRange validator on an input component named quantity:

<h:inputText id="quantity" size="4"
      value="#{item.quantity}" >
    <f:validateLongRange minimum="1"/>
<h:message for="quantity"/>

This tag requires the user to enter a number that is at least 1. The size attribute specifies that the number can have no more than four digits. The validateLongRange tag also has a maximum attribute, which sets a maximum value for the input.

The attributes of all the standard validator tags accept EL value expressions. This means that the attributes can reference backing bean properties rather than specify literal values. For example, the validateLongRange tag in the preceding example can reference a backing bean property called minimum to get the minimum value acceptable to the validator implementation, as shown here:

<f:validateLongRange minimum="#{ShowCartBean.minimum}" />