3
I am developing a system using Java, Maven, Hibernate, Primefaces and Mysql database. Within this system, I have created a program to record the amount of rainfall that occurs on the day.
My table Pluviometro
has the fields for the (auto increment code, location, date and amount of rain).
When I initialize the screen, I have one @PostContruct
that initializes my object Pluviometro
. After initialization, fill in the 3 fields of the table and click on write.
By clicking the "save" button it calls the method to save the data but the object Pluviometro
enough null
. Can someone give me a hint of what might be going on?
@PostConstruct
private void startDeTela(){
PluviometroDAO pluviometroDAO = new PluviometroDAO();
pluviometros = pluviometroDAO.listar("dataDeApontamento");
pluviometro = new Pluviometro();
carregaSelectItens();
}
public void novo(){
pluviometro = new Pluviometro();
}
public void salvar(){
PluviometroDAO pluviometroDAO = new PluviometroDAO();
try{
pluviometroDAO.merge(pluviometro);
Messages.addGlobalInfo("Apontamento Registrado Com Sucesso.");
novo();
}catch(RuntimeException erro){
erro.printStackTrace();
}
}
Hello! It’s not clear where it comes from
null
. The save button calls which method? Furthermore, I recommend avoiding this type of annotationPostConstruct
, are rarely needed and in simpler problems ends up more disturbing than helping.– Dherik
Hello Dherik, it reaches null in the save method().
– Antonio Cardoso
How are you instantiating this class? If you make only one
new Classe()
, this annotation@PostConstruct
(spring, right? ) inside it won’t work.– Dherik
You’re using Spring on this project too?
– StatelessDev
Stateless I’m not using Spring.
– Antonio Cardoso
What I find strange is that on my screen is loading the data of the object Pluviometro. I believe this getting right on screen, otherwise weight would give nullPoint error.
– Antonio Cardoso
This annotation
PostConstruct
where’s?– Dherik
She is from javax.annotation.Postconstruct;
– Antonio Cardoso
To get an idea, what I did to test. No objeto Pluviometro tenho os campos (Fazenda, Data e chuva). I created the independent fields, installed them and on my screen instead of pointing directly to the Pluviometro, I pointed to these fields. At the time of saving I gave a new rainfall meter and I set these fields. Is giving the impression that the Object Rainfall Meter is having scope problem.
– Antonio Cardoso
I tried to send the code of how it got, but it was disfigured.
– Antonio Cardoso