JSF <f:validateDoubleRange> Tag

It is used to check that the value of a input field is within a certain range or not. The value must be floating-point or convertible to floating-point.

# <f:validateDoubleRange> TagAttributes

Attribute Description
minimum It is used to set minimum value for this component.
maximum It is used to set maximum value for this component.

# <f:validateDoubleRange> Tag Example

In this example, we are validating user input of double type within specified range. This program will report an error message if input does not validate.

// index.xhtml


<h:outputLabel for="amount">Enter Amount </h:outputLabel>
<h:inputText id="name-id" value="#{user.amount}" validatorMessage="Please enter amount between 1000.50 and 5000.99">
<f:validateDoubleRange minimum="1000.50" maximum="5000.99"/>
</h:inputText><br/><br/>
<h:commandButton value="Submit" action="response.xhtml"></h:commandButton>
</h:form>

// User.java


import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class User{
double amount;
public double getAmount() {
return amount;
}

public void setAmount(double amount) {
this.amount = amount;
}
}

// response.xhtml


<h:body>
<f:view locale="fr">
Amount entered by you: <h:outputText id = "user-name-id" value="#{user.amount}">
</h:outputText>
</f:view>
</h:body>

Output:

// index page

JSF F validatedoublerange tag 1

// index page

JSF F validatedoublerange tag 2

// response page

JSF F validatedoublerange tag 3