I’m encountering an issue where I can’t perform a second consecutive update on any field of a JSF form. The form initially loads with all fields disabled by default. There’s a ‘Modify’ button at the bottom of the form, which, when clicked, allows me to edit any field. However, as I mentioned, the first update works fine, but subsequent updates fail unless I navigate away from the page and then return.
Here is the portion of my Controller where I call the update
. This is where the update operation is triggered:
@Override
public Personne modifierPersonne(Personne Personne, Adresse adresse) throws GererPersonneControllerException {
verifierExistancePersonne(Personne);
List<Adresse> adresses = Personne.getAdresses();
if (adresse.getId() != null) {
List<Long> ids = adresses.stream().map(Adresse::getId).collect(Collectors.toList());
int index = ids.indexOf(adresse.getId());
adresses.set(index, adresse);
Personne.setAdresses(adresses);
} else {
AdresseDedale adresseDedale = new AdresseDedale();
adresseDedale.setRue(adresse.getRue());
adresseDedale.setCommune(adresse.getCommune());
adresseDedale.setCodePostal(adresse.getCodePostal());
adresse.setTypeAdresse(TYPE_ADRESSE.RESIDENCE.getCode());
adresse.setAdresseDedale(adresseDedale);
List<Adresse> adresses1 = new ArrayList<>();
Adresse adresseTosave = adresseDap.create(adresse);
adresses1.add(adresseTosave);
Personne = PersonneDap.find(Personne.getId());
Personne.setAdresses(adresses1);
}
try {
return PersonneDap.update(Personne);
} catch (PersistenceException e) {
logException(e);
}
}
Here is the code responsible for performing the update:
@Transactional(Transactional.TxType.REQUIRED)
public T update(T entity) {
return entityManager.merge(entity);
}