f:convertDateTime tag in JSF


f:convertDateTime is used for validating the date input.

also read:

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)

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

JavaBean (JavaBeatJsfBean.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()
        return "success";


<?xml version='1.0' encoding='UTF-8'?>

<faces-config version="1.2"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">



view in the browser


Leave a Reply

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

Pin It on Pinterest

Share This

Share this post with your friends!