JSF 1.x generic exception handling

后端 未结 6 1054
耶瑟儿~
耶瑟儿~ 2021-02-02 14:25

If I have an exception in my business layer (e.g. a SQL exception in my JDBC connection bean), how can I propagate it with a custom message to a global error.jsp pa

6条回答
  •  无人共我
    2021-02-02 15:08

    The general way to display error message to the user in JSF is to use FacesMessage:

    On Java side:

    ...
    if (errorOccurred) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("An error occurred blabla..."));
    }
    

    and in the JSF (JSP or XHTML) page, simply use the component in your page in order to display the error.

提交回复
热议问题