I am struggling to understand what Vaadin 8 is doing under the hood here. I am writing an addon yet I am not getting consistent results with transferring the state to the AbstractComponentConnector.
In my server side component when I call getState().xxxxx = yyyyy usually this state change is transferred to the component connector. However in my case sometimes it isn’t? Do I need to make sure that getState().xxxx is called in the UI thread via getUI().access() ??
I cannot find any documentation explaining how this all works. Also if I refresh the browser then is the state cleared and reset or is it by default cached in the Vaadin Session? If I understand the background to how and when state is transferred then I’m sure I could work out my issues. Thanks in advance.
All state modifications should take place with the session/UI locked, but that should be automatic as long as done in code that reacts to user events - background threads making such modifications should use UI.access(). The method getState() automatically marks the component as dirty to transmit changes at the end of the processing of the request from the client, whereas getState(false) does not and should be used in most read-only operations.
Typically, only changes to the state are sent to the client, with the server checking which fields have changed before sending changes. The client side supports notifications of state changes by overriding onStateChanged(StateChangeEvent) in the connector (don’t forget to call the superclass method), notifications of changes of specific fields of the state with @OnStateChange(“mystatefield”) and automatically directly calling a method in the widget in case of state change (no code required in the connector) with @DelegateToWidget on a state field.
On refresh, the new browser window content does not have any cached state information, so it requests all the state etc. to be transmitted in the first reply.