FacesContext and what is ClientId

3k Views Asked by At

Can you explain me why we need in String clientId in the method

void addMessage(String ClientId, FacesMessage msg);? Is it true that when client sent an initial request to server then server assign to this client a specific String ClientId. As i understand FacesContext created when aplication deployed and runnig the first time and this FacesContext is unique for application. Is it true?

1

There are 1 best solutions below

2
On BEST ANSWER

Client id in FacesContext#addMessage(String clientId, FacesMessage message) is needed to be able to add a specific message to a specific component. You can either specify a client id of the component you'd like to assign the message to, or null to add the message to the messages stack not tied to a specific component. The latter will be updated in e.g. <h:message for="clientId>, while the latter in e.g. <h:messages globalonly="true">. You can add a message to global messages in case it is not component-specific, for instance, when database operation failed.