During normal operation, everything works well on my Java EE note taking application running on GlassFish 4.1.2 with STATE_SAVING_METHOD set to server. I can open the ViewScoped Note.xhtml client in my Firefox browser; type text in the CKEditor field; select the [Create] button to save the note to the Derby database; edit the text and finally select the [Update] button to update the note information in the database.
The only issue that I have is when I edit my note and don't select create or update before the view expires. When this happens, the server reports a ViewExpiredException, and I see my default PrimeFaces error page.
Luckily, I discovered that I can perform the following steps to save the edited data.
- Select the browser back button.
- Select the browser refresh button.
- Select create or update buttons on the client.
When I select the browser back button, I see the previously edited page. I believe this is because the browser cached the page locally and is displaying the cached version of the previous page. The browser does not appear to communicate with the server when I select the back button.
If I select the create or update button immediately after selecting the back button, I see the ViewExpiredException again.
However, if I select the back button and then the refresh button, I can save or update my edited note.
I believe that selecting the refresh button creates a new view for the page but what I don't understand is why I don't lose my edits. When I select the refresh button, the server reports it creates a new backing bean and goes to the server to get the data for note. I would have expected the server to send this information back to the client and overwrite the edited values but it doesn't. After the refresh, a new view is created (I think?) but the client still has the edited values. When I select the update button the edited values are saved in the database.
I'm very glad that it works this way, because, if it didn't, I would lose my edits every time the view expired.
My question is why does it work this way. What I am missing about the JSF lifecyle that allows the browser to create a new view using a form containing edited data?
I read javax.faces.application.ViewExpiredException: View could not be restored before posting this question. This question builds on that question by specifically looking at what happened to edited data in a form when the page is refreshed when the view is expired which was not addressed in the original question.