Search code examples
vaadinvaadin7

'Integrating JavaScript Components and Extensions' and how to send state changes from JS back to server?


By following tutorial on https://vaadin.com/docs/-/part/framework/gwt/gwt-javascript.html I created a component for FullCalendar js library. It works nice but I can't still figure out how to send changes in getState() on JS side back to server side to persist. Vaadin sends me serverside state object to JavaScript and I can access it as 'this.getState().property' in my JS component part. Now when user does some browser changes to Fullcalendar (e.g. switches view from month to week) and can detect it and store it back to state object "this.getState().viewName='yyy'" But these changes are not synced back to server so my server side code can't see it in my state JavaBean ...

I also read this article http://vaadinsnippets.blogspot.cz/2012/10/smooth-integration-of-vaadin-7-and.html but still no idea how it should work like. Any hint?


Solution

  • You can't really change "shared state" on the client. From the Vaadin docs https://vaadin.com/docs/-/part/framework/gwt/gwt-shared-state.html:

    [shared state] should be considered read-only on the client-side, as it is not serialized back to the server-side.

    I think what you're looking for is RPC:

    RPC calls from the client-side to the server-side are made through an RPC interface that extends the ServerRpc interface. A server RPC interface simply defines any methods that can be called through the interface.

    https://vaadin.com/docs/-/part/framework/gwt/gwt-rpc.html