Load Ondemand MenuBar

Hello good day

I have a question, I’m doing some tests with the MenuBar and would need load ondemand, because if I have to load many items and need to reduce the number of queries to the database. that I could do with a tree because it has a method that is expand and collapse, the menubar has something similar I can use?

regards

Hello, Ronaldo.
Sorry, I didn’t get how menuBar and queries to a database are related to each other? Do you store the items of menu in the Database? Even in this case (which is a bit strange) I don’t understand why do you have a lot of queries to the database.
Even if you have thousand of menu items in a menubar (which will be really hard to use) it should be fast enough. Can you describe the problem in more detail.

It is absolutly not strange to store your menu structure in a db… How would you implement CMS functionality then? But you are right with the number of queries, but i think he means something like lazy loading, so that not all data has to be loaded at once (i think the tree supports it).

Rolando i don’t think Vaadin has something like lazy-loading for the MenuBar, but you can structure the MenuBar just like you can structure a Tree using sub-menus like this:

MenuBar bar = new MenuBar();
MenuItem item1 = bar.addItem("Item 1", null);
MenuItem item11 = item1.addItem("Item 1.1", null);
item11.addItem("Item 1.1.1", null);

Yes, Felix, you are right. If you have a complicated menu structure which could be change at runtime storing it in the DB can be an option. And yes there is no lazy-loading support for the MenuBar in Vaadin framework. However there is and add-on https://vaadin.com/directory#!addon/lazyloadwrapper, I have not actually used it, but might be usefull.

But issue with lazy-loading is that the menu can be not very responsive, so you need to fetch from DB not only items you have, but also next expected items to be shown. And with menu it could be really tricky.
For example in vaadin table, where is lazy loading, we fetch about +40 rows from the first and last visibule rows, this helps to avoid extra calls to the server when user gets the next row after the last shown.

Try
CustomMenuBar
. It has some more feature. You can use it as NativeSelect for multi select mode.