Saturday, November 10, 2012

Dirty way to handle browser close action in JSF

There is a requirement where I need to do some update in the backing bean before exit the browser. Unfortunately JSF doesn't have such event handling for me. Googling around doesn't seems much help, thus I choose to use the dirty way by simulating a click event to trigger the function called in backing bean when unload event is invoke.

Here is the code:

  1. Put a commandLink in hidden form and execute the click simulation in JavaScript when page is unload.
  2. When the unload event is invoked, click event is triggered, and doCloseProcess will get trigger.
  3. Update the necessary stuff there then done.

No comments: