Exception JSF Delete from Database [duplicate]
This question already has an answer here:
catch DB exception in JSF+EJB application
2 answers
Letting the presentation layer (JSF) handle business exceptions from service layer (EJB)
1 answer
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!"));
}
}
So 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.
Thanks for your help!
Felix
java jpa jsf java-ee
marked as duplicate by f1sh, BalusC
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
catch DB exception in JSF+EJB application
2 answers
Letting the presentation layer (JSF) handle business exceptions from service layer (EJB)
1 answer
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!"));
}
}
So 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.
Thanks for your help!
Felix
java jpa jsf java-ee
marked as duplicate by f1sh, BalusC
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11
add a comment |
This question already has an answer here:
catch DB exception in JSF+EJB application
2 answers
Letting the presentation layer (JSF) handle business exceptions from service layer (EJB)
1 answer
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!"));
}
}
So 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.
Thanks for your help!
Felix
java jpa jsf java-ee
This question already has an answer here:
catch DB exception in JSF+EJB application
2 answers
Letting the presentation layer (JSF) handle business exceptions from service layer (EJB)
1 answer
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!"));
}
}
So 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.
Thanks for your help!
Felix
This question already has an answer here:
catch DB exception in JSF+EJB application
2 answers
Letting the presentation layer (JSF) handle business exceptions from service layer (EJB)
1 answer
<h:message for="deleteButton"/>
<h:commandButton id="deleteButton" value="Delete"
action="#{filmView.deleteRow(film)}" />
<h:message for="deleteButton"/>
<h:commandButton id="deleteButton" value="Delete"
action="#{filmView.deleteRow(film)}" />
java jpa jsf java-ee
java jpa jsf java-ee
asked Nov 12 '18 at 16:46
Felix
267
267
marked as duplicate by f1sh, BalusC
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by f1sh, BalusC
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11
add a comment |
1
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11
1
1
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11
add a comment |
1 Answer
1
active
oldest
votes
Ideally your ManagedBean should handle screen messages.
The best way is throw the error from DAO to your Service layer.
On Service layer you can throw again to your ManagedBean and show the message.
On your FilmDAO.java:
public void delete(int id) throws Exception {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
}
On your FilmService.java:
public void delete(int id) throws Exception {
filmDAO.delete(id);
}
On your FilmMB.java:
try {
filmService.delete(id);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage("Removing dataset(ID:" + id + ") is not possible,
because it's used in another dataset!"));
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ideally your ManagedBean should handle screen messages.
The best way is throw the error from DAO to your Service layer.
On Service layer you can throw again to your ManagedBean and show the message.
On your FilmDAO.java:
public void delete(int id) throws Exception {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
}
On your FilmService.java:
public void delete(int id) throws Exception {
filmDAO.delete(id);
}
On your FilmMB.java:
try {
filmService.delete(id);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage("Removing dataset(ID:" + id + ") is not possible,
because it's used in another dataset!"));
}
add a comment |
Ideally your ManagedBean should handle screen messages.
The best way is throw the error from DAO to your Service layer.
On Service layer you can throw again to your ManagedBean and show the message.
On your FilmDAO.java:
public void delete(int id) throws Exception {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
}
On your FilmService.java:
public void delete(int id) throws Exception {
filmDAO.delete(id);
}
On your FilmMB.java:
try {
filmService.delete(id);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage("Removing dataset(ID:" + id + ") is not possible,
because it's used in another dataset!"));
}
add a comment |
Ideally your ManagedBean should handle screen messages.
The best way is throw the error from DAO to your Service layer.
On Service layer you can throw again to your ManagedBean and show the message.
On your FilmDAO.java:
public void delete(int id) throws Exception {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
}
On your FilmService.java:
public void delete(int id) throws Exception {
filmDAO.delete(id);
}
On your FilmMB.java:
try {
filmService.delete(id);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage("Removing dataset(ID:" + id + ") is not possible,
because it's used in another dataset!"));
}
Ideally your ManagedBean should handle screen messages.
The best way is throw the error from DAO to your Service layer.
On Service layer you can throw again to your ManagedBean and show the message.
On your FilmDAO.java:
public void delete(int id) throws Exception {
em.createQuery("delete from Film where film_id=" + id).executeUpdate();
}
On your FilmService.java:
public void delete(int id) throws Exception {
filmDAO.delete(id);
}
On your FilmMB.java:
try {
filmService.delete(id);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage("Removing dataset(ID:" + id + ") is not possible,
because it's used in another dataset!"));
}
answered Nov 12 '18 at 17:04
ℛɑƒæĿ
1,01621125
1,01621125
add a comment |
add a comment |
1
Why is not a good solution? Does it work or not? Try to identify your problem: is it jpa related or jsf? Can you catch the exception? Can you show a Faces Message?
– perissf
Nov 12 '18 at 16:56
@perissf It is working, but my problem is that i went from the bottom layer directly to the view and not go from one layer to another and I thought it would be possible to do the exception handling directly on the view.
– Felix
Nov 12 '18 at 17:11