Program structure in Vaadin - handling events from another class

Hi!

I have got an application class which is using mainview (called MainView.java). That mainview is using JPAContainerCustomField-component as a top part of the view (Called CountrySelector.java). CountrySelector implements ClickListener. Depending on the choice of the user has done in top part of the page (CountrySelector), lower part is downloaded again (the whole mainView). How can I implement that one. MainView should also know what user has chosen in CountrySelector. Any idea, listeners or just spaghetti?

Thanks,
Sami

in Finnish:

Minulla on Vaadin-sovellus, joka käyttää mainView-luokkaa rakentaakseen osan käyttöliittymästä. MainView.java taas kayttaa countrySelector-luokkaa (JPAContainerCustomField, joka implementoi ClickListernerin) sivun yläosan hakutoiminnon luomikseksi. Siinä on siis ihan normaali country-alasvetovalikko ja city-alasvetovalikko ja vielä yhtiö alasvetovalikko eli käyttäjä valitsee siinä firman. Sen jälkeen painetaan nappia ja ohjelman kulun pitäisi mennä niin, että ohjelmalla on nyt hallussa tuo kyseinen valittu firma ja sen perusteella pitäisi päivittää mainView-luokan muodostama näkymä. Saanko millään listener-kikkailulla tehtyä tätä eli kun selectorissa painetaan nappia click niin mainView tietää tämän ja jatkaa normaalia kulkuaan…

Kiitti!
Sami

I am not really sure I understood your layout from your description. I felt it to be something like :


|---------------------------|
| MainView                  |
| |-----------------------| |
| | CountrySelector       | |
| |-----------------------| |
| |-----------------------| |
| | Other Content         | |
| |-----------------------| |
|---------------------------|

And what you want to do is, when CountrySelector changes, you want to change “Other Content”.
You can do that by using this kind of code in your click listener :


MainView.removeComponent(currentContentRoot);
currentContentRoot = newContentRoot;
MainView.addComponent(newContentRoot);

Or I find it easier to leave a layout in MainView as “contentRoot” and then do :


contentRoot.removeAllComponents();
contentRoot.addComponent(newContent);

Like this you are sure your content ends up always in the same place (inside contentRoot) and the layout is cleaner

Hi!

You got it exactly right, I meant just that. CountrySelector is a customField and there is three comboBoxes and one submit button to make a query to DB. After user has clicked the Button, program should continue in mainView.java and fetch new data to the mainview from DB with parameter user selected in countrySelector. Should I just make a normal getter-method to the CountrySelector and transfer button to mainview and when user clicks the button, I just call the getter etc.

I’ll try your code later today…

Thanks a lot, it always make me happy when somebody understands what I am trying to say and ask :slight_smile:
Sami

I asked the same thing little bit differently here:

https://vaadin.com/forum/-/message_boards/view_message/1128100