I have a dataTable
and in the last column I have an edit button that opens a dialog
with a field to fill. When I click on edit the table is updated with the edited data, however if I give an F5 the old data will return to appear in dataTable
.
Edit method in bean:
public void pausarTarefa(){
System.err.println("Pausar");
try {
tarefa.setStatus("Pausado");
tarefa.setDataFim(new Date());
TarefaDAO tarefaDAO = new TarefaDAO();
tarefaDAO.editar(tarefa);
FacesUtil.adicionarMsgInfo("Tarefa Pausada com Sucesso");
tarefa = new Tarefa();
} catch (RuntimeException e) {
FacesUtil.adicionarMsgErro("Erro ao Pausar Tarefa");
e.printStackTrace();
}
}
Method that fills the list used in the dataTable:
@PostConstruct
public void listar() {
listaTarefa = new ArrayList<>();
System.err.println("Metodo Listar");
try {
TarefaDAO tarefaDAO = new TarefaDAO();
listaTarefa = tarefaDAO.listarPorUsuario(usuarioBean
.getUsuarioLogado());
} catch (RuntimeException e) {
FacesUtil.adicionarMsgErro("Erro ao listar tarefas: "+e.getMessage());
}
}
The scope of the bean is ViewScoped
.
In the database the data is correct after editing, it's just the dataTable that brings the old data. Can anyone help?
DataTable:
p:dataTable value="#{tarefaBean.listaTarefa}" id="tarefaTable"
var="tarefa" style="margin-top: 20px"
emptyMessage="Nenhuma Tarefa Encontrada. " rows="10"
paginator="true" paginatorAlwaysVisible="false"
paginatorPosition="botton">