I have a Java Spring MVC application, with Hibernate and JPA and HTML interface.
I have two forms that depend on the class CadernosCadastrados and their attributes.
Forms have the following names, cadastrodecadernos, change.
In the first form that is cadastrocaderno I enter the data of a new Caderno, just detail some fields like id, Number, date, whoSigned, whoReceived in ° Cadernos, just that and I have save in the bank and a new ID is created for this record.
When I do a search, in the id = 1 case that was generated by the system, a form with the data of the first previous form is displayed, this data is previewed what I do is just add new data in this second form, filling in the new data, has a checkbox in this form with the attributes StatusPendentes and Ended statuses where I choose Pending or Finished, so that the save command is saved in the database. let's say I opted for the End state checkbox is saved in the database as Ended status.
When I do the search again, in case id = 1 it will fall on the same page to change, detail if I typed in the search id = 1 it has to return a message on the screen, "This notebook is finalized can not be changed ", because I registered in the previous register as Status completed.
Method ID of the ControllerCode class that is called when I do a search by ID and shows the results of the form, both for StatusStatus or EndIndex status, if it is terminated, has to return the "This bla bla" message is currently returning the message for both statuses as Endpoints status.?
@GetMapping("id")
public String buscarNumeroID(@Valid CadernosCadastrados objeto, Model model, boolean statusPendentes, boolean statusFinalizados, Long id) {
List<CadernosCadastrados> cadernos = daoCadernosCadastrados.buscarNumeroID(id);
if(cadernos.equals(cadernos) != statusFinalizados) {
model.addAttribute("mensagem", "Este caderno está finalizado não
pode ser alterado!");
}
if(cadernos.equals(cadernos) != statusPendentes) {
model.addAttribute("cadernos", cadernos);
return "public/alterar";
}
return "public/sucessos";
}
Dao method, of the ID, where I search the ID data saved in the database.
public List<CadernosCadastrados> buscarID(Long id) {
TypedQuery<CadernosCadastrados> query = entityManager.createQuery(
"SELECT d FROM CadernosCadastrados d WHERE d.id = :id order by id desc", CadernosCadastrados.class);
query.setParameter("id", id);
return query.getResultList();
}
ControllerClass Class change method, where I bring the list and have it save the new records from the previous form.
@RequestMapping("alterar")
public String alterar(CadernosCadastrados objeto, Long id, BindingResult result, Model model, boolean statusPendentes, boolean statusFinalizados) {
List<CadernosCadastrados> cadernos = daoCadernosCadastrados.buscarNumeroID(id);
daoCadernosCadastrados.alterar(objeto);
return "public/sucessos";
}
Change method of the ControllerCode class where I save the data from the previous form and thus save the data in the database.
public void change (CadernosCadastrados objeto) {
entityManager.merge(objeto);
}