On clicking the Submit button I have to do application/business level validations and associate the error message to a link. As I cannot do that is there any way that I can place the error message on top of the link.
My validation for business logic is in the action method
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("ERROR MESSAGE");
message.setDetail("ERROR MESSAGE");
FacesContext.getCurrentInstance().addMessage("linkId", message);
Help is greatly appreciated
The first argument of
FacesContext#addMessage()must be the client ID, not the component ID. The client ID is whatever you see as ID of the HTML element in the generated HTML output (as you can see by rightclick page and View Source in browser). For JSF input and command components in a form this is usually prefixed with the ID of the form.So, for the following link,
you should be adding the message as follows:
However, the more canonical approach for displaying global messages as you would do from within an action method is just using
<h:messages globalOnly="true" />which you can fill with messages with anullclient ID.So,
with
See also: