Is there any way to register event listeners for components at a central point like the bean?
Is something like this possible?
@PostConstruct
public void setup() {
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot view = facesContext.getViewRoot();
view.getComponentByName("toolBar:save").addActionListener(com.sample.SaveListener);
view.getComponentByName("form:save").addActionListener(com.sample.SaveListener);
}
Not all components are necessarily available during bean’s (post)construction. The bean will be constructed whenever EL needs to resolve
#{bean}for the first time, which may be too early. Do it during the pre render view event instead.Add the following tag to your view:
Then you can do the necessary job in that method: