How to find element in UI

Hi guys I am using vaadin 8 and I am struggling to do, maybe a simple thing.

My UI is divided in two, on the left side I have a menu, on the right side I have the content of the current page.
The left side, has to be dinamic, I explain better.

In the normal navigation, when, for example, I display a table (which has also some action button like edit), the menu on the left side is always the same. But, when I click on the edit button, I want that the menu on the left side, change with only back button.

The problem that I have:

My class which extends UI creates only the left menu, then the navigation fill the right part(I have for example a view which fill the page which various elements like a table, label etc). In this case I reached a solution (maybe not the best, but it works). I am able to change the left side where I want, but I have another problem.
When I am in the edit, in the right side I have a form with save and cancel button. I found a solution that when the form is changed and I click on back button, I show a message to discard or save changes. But I don’t know what can I do it, when I click on the back button, presents in the left menu.

I hope I was clear. I attach an image in order to clarify better.

Normal navitagion
https://ibb.co/bNrz3G

When I click on pencil button (of the prev image), I view:

https://ibb.co/iYBcqw

Maybe I can get the back button on the left menu, in current view trough id?
Please help me!

Hi Fabio,
are you using Navigator for changing views?
If so, you could implement beforeLeave method in your View implementation and share the same code you are using in the button listener.

Be aware that beforeLeave was introduced since Vaadin 8.1; if you are using an earlier version you can reach the same result registering a ViewChangeListener on Navigator.

HTH
Marco

Hi Marco,
your answer is awesome for me!

I solved also other issue related on this.

Thanks!!!