☰ See All Chapters |
JSF <f:validateDoubleRange> Tag
<f:validateDoubleRange> tag is used to validate the range of the Integer input. The property of managed bean which is bound this input can be of type double, whereas for <f:validateLongRange> can be used with inputs which are bound to property of type int or long. This tag has below two attributes.
minimum: used to validate for minimum double value
maximum: used to validate for maximum double value
<h:outputText value="Enter your salary" />
<h:inputText id="sal" value="#{helloBean.salary}"
validatorMessage="Salary is not in the range 20000.00-100000.00 "
converterMessage="Please enter double value">
<f:validateDoubleRange minimum="20000.00" maximum="100000.00" />
</h:inputText>
<h:message for="sal" style="color:red" />
JSF <f:validateLength> Tag Example
pom.xml
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.java4coding</groupId> <artifactId>JSF_Validator</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.6</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.6</version> </dependency> </dependencies> <build> <finalName>JSF_Validator</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.1</version> <configuration> <source>1.9</source> <target>1.9</target> </configuration> </plugin> </plugins> </build> </project> |
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "https://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> </web-app> |
HelloBean.java
package com.java4coding;
import javax.faces.bean.ManagedBean;
@ManagedBean public class HelloBean {
private double salary;
public double getSalary() { return salary; }
public void setSalary(double salary) { this.salary = salary; }
public String display() { return "second"; } } |
first.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" xmlns:h="https://xmlns.jcp.org/jsf/html" xmlns:f="https://xmlns.jcp.org/jsf/core">
<h:head></h:head> <h:body> <h:form> <h:panelGrid columns="4"> <h:outputText value="Enter your salary" /> <h:inputText id="sal" value="#{helloBean.salary}" validatorMessage="Salary is not in the range 20000.00-100000.00 " converterMessage="Please enter double value"> <f:validateDoubleRange minimum="20000.00" maximum="100000.00" /> </h:inputText> <h:message for="sal" style="color:red" /> </h:panelGrid>
<h:commandButton value="LOGIN" action="#{helloBean.display}" /> </h:form> </h:body> </html> |
second.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" xmlns:h="https://xmlns.jcp.org/jsf/html" xmlns:f="https://xmlns.jcp.org/jsf/core">
<h:head></h:head> <h:body> <h1> <h:panelGrid columns="2"> Salary is <h:outputText value="#{helloBean.salary}" /> </h:panelGrid> </h1> </h:body> </html> |
Eclipse project directory structure
Output
All Chapters