Pessoal !!!
Estou tentando criar um converter para evitar data “15/30/2012” onde o primefaces converte esses meses a mais adicionando no ano. Talvez tenha um modo simples de fazer já no componente mas não encontrei.
Então fiz o converter :
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
@FacesConverter(value = "converteData")
public class ConverteData implements Converter {
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
df.setLenient(false);
try {
return df.parse(arg2);
} catch (Exception e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player"));
}
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
try {
df.setLenient(false);
String d = df.format((Date) arg2);
return d;
} catch (Exception e) {
return "";
}
}
}
Até funciona mas a mensagem não é exibida no meu growl. E não é problema no growl pois exibe mensagm em outros campos.
Meu calendar está assim:
<p:calendar value="#{pedidoMB.dataEmissao}"
style="width: 100px;"
size="10"
pattern="dd/MM/yyyy"
converter="converteData"
converterMessage="Erro ao converter data de emissão" >
</p:calendar>