JAVA SERVER FACES (JSF)

JSF PROJECTS

JSF PROJECT 1

JSF Examples

JSF EXAMPLE

adplus-dvertising
ConvertDateTime Tag Example
Previous Home Next

Tag description: JSF <f:convertDateTime> Tag is is register a DateTimeConverter instance on UIComponent associate with the enclosing parent tag. DateTimeConverter is Converter implementation for java.util.Date values use getAsObject() method parses a String into a java.util.Date.

Code

<f:convertDateTime>

Example :

Step 1: Welcome page of Example

<%--
   Nam= 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">

Step 2: ManagedBean class for provide logic in program

<%--
   Nam= 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:convertDateTime> Example"/></h1>
<h:form id="convertDateTime">
<%-- Dispiay Error message --%>
<h:message for="birthdate" style="color:red" />
<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
   <h:outputLabel value="Enter the Date of Birth"/>
<h:inputText id="birthdate" size="20" required="true"
value="#{convertDateTime.birthdate}" >
<%-- Tag <f:convertDateTime> use--%>
<f:convertDateTime type="date" dateStyle="short" />
</h:inputText>
   <h:commandButton value="Submit Date" action="#{convertDateTime.submit()}" />
</h:panelGrid>
<BR><BR>
   <%-- Display result--%>
<h:panelGrid rendered="#{convertDateTime.flag!= false}">
Date of Birth:<h:outputText value="#{convertDateTime.birthdate}" />
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>

Output :

Previous Home Next