The ViewExpiredException (javax.faces.application.ViewExpiredException
) occurs when the view state of a form is no longer available on the Engine. Normally this will only happen if the user is working with multiple tabs or has navigated too far back in the browser's history.
View State
The view state is the state of a form and all its components and their state on the server. Each time a new form is generated, this results in a new view state.
The view state id is sent to the browser in a hidden input field called javax.faces.ViewState
. So if a form is submitted and the corresponding view state specified in the hidden input field is no longer available, this results in a ViewExpiredException exception.
View states are stored in the http session on the Engine. The best thing about the view state is that it effectively prevents CSRF attacks. This means that only the client that requested the form can actually submit it.
Why does the View expire?
This usually happens when the view state of a From is no longer available on the Engine.
But why it is not available can have many reasons:
Html Dialog was closed
The Html Dialog is closed when the User Dialog Exit End Process element is executed and the process proceeds to the next element in the business process after the User Dialog. In this case, the view state of this dialog is explicitly removed. So if the user presses back in the browser and tries to submit the form again, they will get a ViewExpiredException. This is because it is not allowed to go back to a From and manipulate the date afterwards in a workflow application where the task has already been closed.
There is even another case: When the user submits a form, which closes the html dialog, but because the user still sees the old view until the next page is loaded. It is possible that the user submits the form of the already closed dialog again. This will also result in a ViewExpiredException.
☑An Ajax loading status can prevent this. This has even been improved in Axon Ivy 10.0.14. See follow-up post.
Session Timeout
The session on the Engine is timed out after a period of inactivity, usually 30 minutes.
So if the user opens a form and then takes a break longer than the session timeout. When they come back, they will get a ViewExpiredException when submitting the form.
Session not found
This can happen if the user deletes the session cookie from their browser's cookie store. Or it can happen when the admin actively terminates a session on the Engine.
View per Session Limit
There is a maximum number of view states that will be kept per session. So if the user opens too many views, perhaps even in multiple tabs, they may reach this limit and get a ViewExpiredException.
Here is an old answer that gives a bit more insight. However, it is not recommended to change these settings, as this can have a big impact on the memory consumption of the Engine or the user experience:
https://answers.axonivy.com/questions/1035/viewexpiredexception
Engine reboot
When the Engine is restarted, all sessions and view states are lost. So if the user submits a form that was generated before the reboot, and the Engine is now running again, they will get a ViewExpiredException.
Logging
By default, the ViewExpiredException is not logged on the Engine. This is because it can happen very often and is not a fault of the Engine itself, but of user behaviour.
Exception handling
There is even a separate AJAX exception handler for this exception. See
https://developer.axonivy.com/doc/10.0/designer-guide/user-interface/user-dialogs/html-dialog-error-handling.html#view-expired-exception