5
I have a dataTable
where I display some data but the date is coming in format yyyy-mm-dd
how do I change the format of this date so that I can display it correctly in my dataTable
? And where do I do this formatting? In Bean or DAO?
Here is my method that takes the database data and fills the dataTable
:
@PostConstruct
public void listar(){
try{
TarefaDAO tarefaDAO = new TarefaDAO();
listaTarefa = tarefaDAO.listarPorUsuario(usuarioBean.getUsuarioLogado());
}catch(RuntimeException e){
}
}
DAO:
@SuppressWarnings("unchecked")
public List<Tarefa> listarPorUsuario(Usuario usuario) {
Session sessao = HibernateUtil.getSessionFactory().openSession();
List<Tarefa> lista = null;
try {
Query consulta = sessao.getNamedQuery("Tarefa.listarPorCodigo");
consulta.setParameter("usuario", usuario);
lista = consulta.list();
} catch (RuntimeException ex) {
throw ex;
} finally {
sessao.close();
}
System.out.println("LISTA NO DAO:" + lista);
return lista;
}
Declaration of variables that are dates in the Model:
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_inicio", nullable = false)
private Date dataInicio;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_fim", nullable = false)
private Date dataFim;
I want to display the date in the format dd-mm-yyyy
I think you’ve asked that question before.
– Maniero