JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

f:convertDateTime tag in JSF

July 4, 2008 by Krishna Srinivasan Leave a Comment

Introduction

f:convertDateTime is used for validating the date input.

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

If the user enters any invlid input, it will throw the error message to the screen. Also it allows the user to specify the apttern of date format using the ‘pattern’ attribute.

JSP File (index.jsp)

[code lang=”html”]
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<body>
<f:view>
<h:form>
<h:message for="dateTime"/>
<h:inputText id="dateTime" value="#{jsfBean.number}">
<f:convertDateTime type="date" pattern="dd/mm/yyyy"/>
</h:inputText>
<h:commandButton action="#{jsfBean.submit}" value="submit"/>
</h:form>
</f:view>
</body>
</html>[/code]

JavaBean (JavaBeatJsfBean.java)

[code lang=”java”]
package javabeat.jsf;

/**
* source : www.javabeat.net
*/
public class JavaBeatJsfBean {
private String field;

public String getField() {
return field;
}

public void setField(String field) {
this.field = field;
}
public String submit()
{
System.out.println(this.field);
return "success";
}
}[/code]

faces-config.xml

[code lang=”xml”]
<?xml version=’1.0′ encoding=’UTF-8′?>

<faces-config version="1.2"
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_1_2.xsd">

<managed-bean>
<managed-bean-name>jsfBean</managed-bean-name>
<managed-bean-class>javabeat.jsf.JavaBeatJsfBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

</faces-config>[/code]

view in the browser

jsf-2

Filed Under: JSF Tagged With: JSF Tags

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved