Wednesday, August 16th, 2017

Date showing wrong in JSF outputText or with dataTable

2

Date showing wrong in JSF outputText or with dataTable
Some times in , h:outputText with dataTable or without , java.util.Date showing wrong, means one date before the actual date is showing. We can solve this problem using Converter. One example…
Some times in , h:outputText with dataTable or without , java.util.Date showing wrong, means one date before the actual date is showing.
We can solve this problem using Converter.
One example :

DateConverter.java

package com.converter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
/**
* This class is is used to convert a date to dd-MMM-yyyy format
*
*/
public class DateConverter implements Converter {
public String getAsString(FacesContext context, UIComponent c, Object object)
throws ConverterException {
if(object!=null && !object.toString().equals(“”)){
final Date date = (Date) object;
String dt=null;
if(date!=null){
SimpleDateFormat formatter=new SimpleDateFormat(“dd-MMM-yyyy”);
dt=formatter.format(date);
return dt;
}}
return null;
}
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
throws ConverterException {
return null;
}
}

In faces-config.xml

dateConvert
com.converter.DateConverter

In your jsp page

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • RSS
  • Technorati
  • Twitter

Comments

2 Responses to “Date showing wrong in JSF outputText or with dataTable”
  1. Juliano says:

    Thank’s!
    This solve my problems with h:outputText and date!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Secure Linux Web Hosting