CodesJava

Easy learning with example program codes

Jsf validateLongRange example


JSF f validateLongRange tag:

JSF f: validateLongRange tag is used to validate the range of a numeric value.

Syntax:

<f:validateLongRange minimum="m" maximum="n" />

JSF f validateLongRange tag attribute:

Attribute Description
1. minimum It specify minimum long value within an optional range
2. maximum It specify maximum long value within an optional range

Example:

test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
	<h:head>
		<title>JSF f validate long range example.</title>
	</h:head>
    <h:body>
    	<h2>JSF f validate long range example.</h2>
 
    	<h:form>
    	   <h:inputText id="ageId" 
    	     label="Age: " value="#{test.age}">
    	     <f:validateLongRange minimum="10" maximum="150" />
    	   </h:inputText>
    	   <br/>
    	   <h:message for="ageId" style="color:red" />
    	   <br/>
    	   <h:commandButton value="Submit" action="success"/>  
    	</h:form>
 
    </h:body>
 
</html>

Test.java

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 
/**
 * Managed bean.
 * @author codesjava
 */
@ManagedBean(name="test")
@SessionScoped
public class Test {
	private int age;
 
	public int getAge() {
		return age;
	}
 
	public void setAge(int age) {
		this.age = age;
	}	
}

welcome.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
	<h:head>
		<title>JSF f validate long range example.</title>
	</h:head>
    <h:body>
    	<h2>JSF f validate long range example.</h2> 
    	<h3>Age: <h:outputText value="#{test.age}"/></h3> 	
    </h:body>
 
</html>

faces-config.xml

<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xi="http://www.w3.org/2001/XInclude" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
 
</faces-config>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    	xmlns="http://java.sun.com/xml/ns/javaee" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 
    <servlet>
        <servlet-name>faces</servlet-name>
        <servlet-class>
         javax.faces.webapp.FacesServlet
	<servlet-mapping>
        <servlet-name>faces</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
 
</web-app>

URL:

http://localhost:7001/JSFExample33/faces/test.xhtml

Output:

JSF example33-1
 
Enter Value.
JSF example33-2
 
Click Submit button.
JSF example33-3
 
Download this example.
 

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki