Keeping state in widget after setVisible

My debugging session showed me that calling setVisible(false) then setVisible(true) on a server side component of a widget causes the widget to be reinstantiated. Thats essentially means every time I hide and show my widget the default constructor will be called.

My problem is I have and underlying VTextField instance in my widget which loses its value when that happens. I create the VTextField in the constructor with

textField = GWT.create(VTextField.class); and save it in a private final field. I set the textfield text with the setText method.

How do I keep the textfield’s text after reinstantiating the whole widget?

Problem solved. Shared state came to rescue. I just store the textfield’s text in the state and let shared delegate to widget.

@DelegateToWidget public String displayedText = “”;