If your method throws an exception or, more generally, there is a controlled error or warning and you must show to user this error then you can add a FacesMessage in your JSF page in this way:
try {
yourCode...;
}
catch (YourApplicationException e) {
FacesMessage messaggio=new FacesMessage(e.getMessage());
FacesContext context=FacesContext.getCurrentInstance();
context.addMessage(null,messaggio);
return null;
}
In your jsp page you have to add this code:
<h:messages globalOnly="true" />
The
globalOnly attribute because it will display all generic error messages, those messages with the first parameter of
addMessage method equals to
null.
If you want display errors about a single field the you must specify the "validator" attribute of that field!
Theoretically, you could specify the id field in the first parameter of "addMessage" method but with JSF 1.1 seems not work!