JSF 2 validateDoubleRange example

f:validateDoubleRange” is a JSF range validator tag, which is used to validate the range of a floating point value. For example,

<h:inputText id="salary" value="#{user.salary}">
	<f:validateDoubleRange minimum="10.11" maximum="10000.11" />

When this form is submitted, the validator will make sure the “salary” value is within the range from “10.11” to “10000.11”.

“f:validateDoubleRange” example

A JSF 2.0 example to show the use of “f:validateDoubleRange” tag to validate the range of a “salary” input field, when the validator failed, display the error message via “h:message” tag.

1. Managed Bean

An user managed bean, with a “salary” property.

package com.mkyong;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
public class UserBean implements Serializable{
	double salary;

	public double getSalary() {
		return salary;

	public void setSalary(double salary) {
		this.salary = salary;

2. JSF Page

JSF XHTML page, show the use of “f:validateDoubleRange” tag to make sure the “salary” input value is within the range from “10.11” to “10000.11”.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"   
    	<h1>JSF 2 validateDoubleRange example</h1>
		<h:panelGrid columns="3">
			Enter your salary : 
			<h:inputText id="salary" value="#{user.salary}" 
				size="10" required="true"
				label="Salary" >
				<f:validateDoubleRange minimum="10.11" maximum="10000.11" />
			<h:message for="salary" style="color:red" />
		<h:commandButton value="Submit" action="result" />

3. Demo

Minimum range validation failed.


Download Source Code


  1. JSF 2 validateDoubleRange JavaDoc
  2. Wiki floating point explanation
author image


Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by


newest oldest most voted

Hi Mkyong,

I have a validation problem in my project i need to put two decimal after point(.)

I am not able to get solution for this problem using can help in this