How to sync client widget state with server state

Hello everbody,

I’m trying to reimplement some widgets I had from GWT in Vaadin by using the new client-side mechanism of Vaadin 7 but I’m having some trouble when it comes to synchronize the client state with the server state (the other way around works fine).

I’m aware that AbstractComponentStatus values are not propagated back to the server. According to the docs RPC is the mechanism to use. I can easily make RPC calls from my client side widgets but they (logically) trigger a POST to the server, which is not exactly what I want. I simply want any post to the server to automatically carry these values to the client without me having to do it explicitly. This is the way I had understood Vaadin components work but I cannot replicate this behaviour with mine.

My widget is based on a GWT TextBox. I have (outside of the widget) a normal Vaadin Button component with a clickListener that basically tries to print on the screen the content of my customized textbox. When I click the button the POST is made but the value of my textbox is always empty once it reaches the server. When changing my textbox for a standard TextField everything works perfectly fine.

I have looked at the source code of the TextField but seems to be using the previous api (not entirely sure, I’m new to Vaadin).

Am I missing something?


I think what you want is to annotate your RPC method with @com.vaadin.shared.annotations.Delayed. This causes any invocations of the method to be queued until some other, non-@Delayed, RPC is invoked. If you’re only interested in the latest state, add lastOnly=true to the annotation.

I’m not an expert in creating a client-side component but did you already have a look at
this Wiki article
You should also have a look at the other Articles in the chapter custom widgets
Hope it helps

Thanks guys, Johannes solution of using @Delayed(lastOnly = true) did the trick. Now the values are passed to the server without an explicit RPC call. Still I find strange this is the only solution, it looks more like a workaround. I guess this should be a very common issue when developing custom widgets.

In Vaadin 6 (and the legacy parts of Vaadin 7) there was this concept of immediate and non-immediate variable changes - the new delayed and non-delayed RPC calls are basically the same thing. Delayed updates are practically an optimization to reduce network traffic - this is not nearly as important these days as it was in the olden times.The fact that so few things in Vaadin 6 were immediate by default has caused a plenty of confusion throughout the years.

I suppose some things could be done more intuitively if we had client-to-server state updates, particularly with field-type widgets, but it would also involve all kinds of complication. Note that in this case, it seems that it’s clicking of that one exact button that should update the server state - not any other immediate RPC call. As a (mostly) server-side framework, this is not really something Vaadin is made for.