Date showing wrong in JSF outputText or with dataTable
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



http://mail-archives.apache.org/mod_mbox/myfaces-users/200605.mbox/%3C467251f60605110247x44c66154rd85f498f1362740a@mail.gmail.com%3E
Thank’s!
This solve my problems with h:outputText and date!