af:message usage |
In this post which has the source file attached also you can see that how you can use af:message in order to show errors that is specific to that a component.
as you know when you generate a general error like the below one
String msg="this is a global message.";the generated error would be catch by af:messages and can be shown inline or popup.
FacesContext ctx = getFacesContext();
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "");
ctx.addMessage(null,fm);
but if you want your message be shown separately for different component or part of the page you can use af:message
in order to generate a message that is related to a specific component in your page you must use below code
getFacesContext().addMessage(panelBox.getClientId(getFacesContext()),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Specific Error", "this error is just for panel box 1"));
panelBox.getClientId(getFacesContext() --> is the id of the component, you can write the id component instead but using the getClientId is error free and standard.
you can see a sample application developed in 11.1.1.3 in the attachment to this post.