---- Julien Martin <[EMAIL PROTECTED]> schrieb:
> Hello Simon,
> 
> Good pointer! Here is what I tried :
> 
> FacesContext.getCurrentInstance().addMessage("companies-netting-process-button",
> new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erreur lors de la copie",
> ex.getMessage()));

I think that's better than passing null as the clientId property, but still not 
quite right.

The clientId of your component should actually be
  companies-netting-process-form:companies-netting-process-button
as you can see by viewing the generated html for your page. A form is a "naming 
container", and "naming containers" add their id as a prefix to all child 
components, just like a parent directory is part of the absolute path to files 
in that directory.

In general, the only safe way to get the clientId of a component is to actually 
call method getClientId() on the component instance. I suggest you use 
component-binding to get the component that you want to attach the message to. 
[1]

Component-binding is generally better avoided, but when you want to attach 
error messages to a specific component, it is the only sensible option.

By the way, when using component-binding, do NOT store the component reference 
on an object that is not request-scoped. Holding on to a component reference 
across different request cycles is very bad for a number of reasons.

[1] In most cases, it is validators which attach messages to specific 
components. Here, there is no problem as the validator already has a reference 
to the UIComponent it is validating.

Regards,

Simon

Reply via email to