views:

74

answers:

1

I was wondering how would I be able to show SQL errors generated during update, delete, select * etc in JSF.

Any help would be appreciated.

+3  A: 

You have three options:

  1. Let the exception bubble up (either declare your action methods throws SQLException, or wrap them in RuntimeException

  2. catch the SQLException and add it as a JSF message, which is more readable. The format is up to you.

    String msg = obtainFormattedMessageFromException(exception);
    FacesMessage facesMessage = 
      new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
    FacesContext.getCurrentInstance().addMessage(null, facesMessage);
    
  3. Don't show them (best option). These exceptions would confuse the user. Instead, log them (using log4j, commons-logging, or whatever) to a log file, which you will be able to read later. Show only a generic message to the user that something went wrong.

Bozho
Option 3 still needs to communicate to the user something went wrong.
Thorbjørn Ravn Andersen
yes, sure. I updated my answer.
Bozho