I’m trying to grasp the main concepts behind TornadoFX, i.e. when and how to use a view model.
Let’s take the following example: I have a main view with a borderpane as root. This borderpane contains another view with a button. When I press this button a REST call is made and when the response is 403 then the main view should be replaced with a login view (WebView) where the user can log in. When the login is successful, an access token is received and stored somehow.
I was thinking about using a response interceptor defined in a view model injected into the main view. When a 403 is intercepted, a boolean property is updated which triggers a call to “replaceWith” in the main view. The login view replaces the main view and when the login is done a scope containing the access token is created and given to the main view with another call to “replaceWith”. The main view then (or the main view model) uses this token to make successive REST calls as long as the token is valid.
Any suggestion how I could model this kind of flow? Make REST calls as long as response is not 403, then show login view and, after successfull authorization, the main view is shown again and the REST call is repeated using the new access token.
Go to Source