Introduction
Part 1 of this series describes a scenario in which your application automatically saves form data on the server and you want to be able to restore forms after your users close and reopen their browsers. The solution works even if the user's browser crashes, or if the user leaves the application without clicking Submit on the Web form.
The sample application included with this article (see Download) contains a typical JSF form named SupportForm.jsp whose data is periodically submitted to the server using the JavaScript functions of the AutoSaveScript.js file. Both SupportForm.jsp and AutoSaveScript.js are described in Part 1, which also shows how to use a JSF phase listener to process Ajax requests without interfering with the application logic.
In this article, you'll learn how to build a thread-safe data repository for keeping auto-saved form data. You'll see how to choose data structures, how to populate them with the form data extracted from the JSF component tree, how to restore the state of the JSF components, how to limit the memory resources of the data repository, and how to implement its persistence. You'll also learn several Web techniques, such as using filters and browser ID cookies.