mary jane
mary jane

Reputation: 542

Vaadin panel shared between pages

I want to create panel object (working as a kind of navigation bar) shared between pages. I want to add buttons dynamically, so it's important to me that all pages share the same object.

However when I add the panel to second page it disappears from the first one! Why is it so?

And maybe any tips how to deal with it? :)

Upvotes: 2

Views: 483

Answers (2)

AndroidHustle
AndroidHustle

Reputation: 1814

I would suggest you take a look at FlexTabSheetNavigationFeeder a component that, to my understanding, is used for creating a universal navigation menu connecting view/content to each of the buttons/tabs of the component.

I use a common library of the Vaadin framework and we have component called SFlexTabSheet doing exactly what it sounds that you want to do.

Upvotes: 1

Henrik Paul
Henrik Paul

Reputation: 67703

The Vaadin component hierarchy allows for one component to be at one place at a time. In other words, you can't have the same Component instance added to two places at the same time.

The best solution would be to move your panel so that the panel is never replaced, only the surroundings. If that's impossible, you need to just recreate the controls for each page.

If your controls are stateful, remember that Properties can be shared between Fields, and all classes extending AbstractFields are Properties, so you can do stuff like

TextField tf1 = new TextField();
layout1.addComponent(tf1);

TextField tf2 = new TextField();
tf2.setPropertyDataSource(tf1);
layout2.addComponent(tf2);

This way your two textfields are backed up by the same Property. So, after the value has changed, your two textfields have the same value.

Upvotes: 3

Related Questions