I'm using Glassfish server 4.1.1, java EE7 web, jdk 1.8 and jsf 2.2
When editing or keeping a record the time or good date also differ between what is stored in the bdd (which is correct) and what the datatable shows (which is incorrect). The following image shows the data table:
and now what is shown in the bdd field (correct date)
Methods get and set of the class and reference to the field of the table in the user class. java
public Date getUpdated () { return updated; }
public void setUpdated(Date updated) {
this.updated = updated;
}
public Date getCreated () { return created; }
public void setCreated(Date created) {
this.created = created;
}
@Column (name="CREATED") @Temporal (TemporalType.TIMESTAMP) private Date created;
@Column (name="UPDATED") @Temporal (TemporalType.TIMESTAMP) private Date updated;
form.xml
<h:outputLabel value="Modificado:" for="updated"/>
<h:inputText id="updated" value="#{usuarioController.selected.updated}" title="Actualizado" disabled="true">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
</h:inputText>
<h:outputLabel value="Creado :" for="created"/>
<h:inputText id="created" value="#{usuarioController.selected.created}" title="Creado" disabled="true">
<br></br>
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
</h:inputText>
Methods in the controller to create and edit a user
public String agregar(){
Date d= new Date();
selected.setCreated(d);
selected.setUpdated(d);
dao.create(selected);
return "/usuario/index";
}
public String edit(int codigo){
selected = dao.find(codigo);
return "/usuario/edit";
}
public String guardar(){
Date d = new Date();
selected.setUpdated(d);
dao.edit(selected);
return "index";
}
PD. I am using the own database of netbeans that is included in the services