I have a problem with my exception handling in JSF.
I want to show an error message on my JSF page when the user can not delete an entry in the database.
<h:message for="deleteButton"/>
<h:commandButton id="deleteButton" value="Delete" action="#{filmView.deleteRow(film)}"/>
public void deleteRow(Film deleteTemp) {
filmService.delete(deleteTemp.getFilmId());
}
public void delete(int id) {
try {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("", new FacesMessage(
"Removing dataset(ID:"
+ id + ") is not possible, because it's used in another dataset!"));
}
}
Is it possible to get this error message into the JSF page and if yes is this better, because I heard that how I do it right now, it is not a good solution.