| Previous | Home | Next |
Tag description: JSF <f:convertNumber> Tag is register a NumberConverter instance on the UIComponent associate with the enclosing parent tag. NumberConverter is Converter implementation for java.lang.Number values use to getAsObject() method parses a String into an java.lang.Double or java.lang.Long.
Code
<f:convertNumber>
Example :
Step 1: Welcome page of Example
<%--
Name= welcomeJSF
--%>
<%@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:converter> Example"/></h1>
<h:form id="converter">
<%--Display Error message --%>
<h:messages for="converter:name" globalOnly="true" style="color:red" />
<h:panelGrid columns="2" cellpadding="2" cellspacing="2" >
<h:outputLabel value="Website name" />
<h:inputText id="name" value="#{converter.name}" required="true" size="30">
<f:converter converterId="ConverterClass" />
</h:inputText>
<h:commandButton action="#{converter.submit()}" value="Submit" />
</h:panelGrid>
<br><br>
<%-- Display result --%>
<h:panelGrid rendered="#{converter.flag != false}" >
Website url: <h:outputText value="#{converter.name}"/>
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>
Step 2: ManagedBean class for provide logic in program
<?xml version='1.0' encoding='UTF-8'?> <!-- =========== FULL CONFIGURATION FILE ================================== --> <faces-config version="2.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-facesconfig_2_0.xsd"> <managed-bean> <managed-bean-name>converterBean</managed-bean-name> <managed-bean-class>r4r.JSF2.converterBean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <!-- == Add Converter class invoked by converterId in JSP == --> <converter> <converter-id>ConverterClass</converter-id> <converter-class>r4r.JSF2.ConverterClass</converter-class> </converter> </faces-config>
Output :
| Previous | Home | Next |