Previous | Home | Next |
Tag description: JSF <f:validateDoubleRange> Tag is register a DoubleRangeValidator instance on the UIComponent associate with the enclosing parent tag. DoubleRangeValidator is a Validator that checks the value of the corresponding component against specified minimum and maximum values.
Code
<f:validateDoubleRange>
Example:
Step 1: Welcome page of Example
<%-- Name= welcomeJSF.jsp --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%-- This file is an entry point for JavaServer Faces application. --%> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>r4r.co.in</title> </head> <body> <h1><h:outputText value=" Tag <f:validateDoubleRange> Example"/></h1> <h:form id="ValidateDoubleRange"> <%-- Error Message display --%> <h:message for="ValidateDoubleRange:balance" style="color:red" /> <h:panelGrid columns="2" cellpadding="2" cellspacing="2" > <h:outputLabel value="Enter your Balance:" /> <h:inputText id="balance" value="#{validateDoubleRange.balance}" required="true"> <%-- Use <f:validateDoubleRange> Tag --%> <f:validateDoubleRange minimum="0000.00" maximum="9999.99" /> </h:inputText> <h:commandButton value="Submit Balance" action="#{validateDoubleRange.submit()}" /> <h:commandButton value="Reset" action="#{validateDoubleRange.reset()}" /> </h:panelGrid> <%-- Display Result --%> <!-- Render is used for indicate the flag position --> <h:panelGrid rendered="#{validateDoubleRange.flag!= false}" > Balance in Account: <h:outputText value="#{validateDoubleRange.balance}" /> </h:panelGrid> </h:form> </body> </html> </f:view>
Step 2: ManagedBean class for provide logic in program.
/* * Save as a validateDoubleRangeBean.java */ package r4r.JSF2; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean(name = "validateDoubleRange") @RequestScoped public class validateDoubleRangeBean { private double balance; //Create a flag with initial value false private boolean flag = false; /* -- Getter/Setter -- */ public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public boolean isFlag() { return flag; } public void setFlag(boolean flag) { this.flag = flag; } /* -- Submit method -- */ public String submit() { flag = true; return "submit"; } /* -- Reset method -- */ public String reset() { flag = false; balance = 00.00; return "reset"; } }
output:




Previous | Home | Next |