Do it in the @PostConstruct method of the request scoped bean which is associated with the requsted JSF page by EL like #{bean}.
@ManagedBean
@RequestScoped
public class Bean {
@PostConstruct
public void init() {
// Here.
}
}
Unrelated to the question, I only wonder why you would ever do it that way? JSF/PrimeFaces offers much nicer ways using <f:ajax> and <p:ajax> and consorts.
Is it the intent to run this during Window's unload or beforeunload events? If so, then I have to warn you that this is not reliable. It's dependent on the browser whether such a request will actually reach the server or not. More than often it won't. Use it for pure statistical or premature cleanup purposes only, not for sensitive business purposes.