Add an one layout few times.

Hello

I know there were a lot of topics this kind but I’ve not found any answers which could satisfied me.
I’ll describe what I want to do and if adding one layout few times is not possible, please give me an alternative.

On my site I want to add a few movies: title, description, director etc. fields. I don’t want to show these informations in table but in a different divs, in a different layout each.

That’s my button click listener (works fine).

                        if (action == Action.ADD) {
                            
                            VerticalLayout vl5 = new VerticalLayout();
                            
                            Label title = new Label(movie.getTitle());
                            Label description = new Label(movie.getDescription());
                            Label director = new Label(movie.getDirector());
                            
                            vl5.addComponent(title);
                            vl5.addComponent(description);
                            vl5.addComponent(director);

                            CL.addComponent(vl5, "right_menu");    
                            movieManager.addMovie(movie);

CL is my custom layout component. The problem is that everytime when I try to add new movie, it’s not happen, it’s just edit the last added movie so there is still one layout.

I need to get a resault like this one:

I hope you understand now why I want to duplicate this layout. If it’s not possible, please give me an alternative. Thank you for your help and time. Cheers

I’ve tried to do something like but still no result:

                        if (action == Action.ADD) {
                            
                            VerticalLayout vl5 = new VerticalLayout();
                            
                            CL.addComponent(new VerticalLayout(new Label(movie.getTitle)), "right_menu");    
      
                     movieManager.addMovie(movie);

Hi Daniel,

the CustomLayout can only add one Component per slot. So if you want to add more than one Component to the slot, you’ll need another VerticalLayout that holds your vl5 layouts:

CustomLayout CL = new CustomLayout([...] ); VerticalLayout rightMenu = new VerticalLayout(); rightMenu.setWidth("100%"); CL.addComponent(rightMenu , "right_menu"); And than add your vl5 layouts to that wrapper layout. You should also define a width of 100% for the vl5 layout so it will span the entire width of the row:

if (action == Action.ADD) {
                            
    VerticalLayout vl5 = new VerticalLayout();
    // add width to layout
    vl5.setWidth("100%")
                            
    Label title = new Label(movie.getTitle());
    Label description = new Label(movie.getDescription());
    Label director = new Label(movie.getDirector());
                            
    vl5.addComponent(title);
    vl5.addComponent(description);
    vl5.addComponent(director);
    
    // Insert to the wrapper layout here:
    rightLayout.addComponent(vl5);    
    movieManager.addMovie(movie);
}

Hello

[s]
Thank you for your answer but I’m afraid it’s not what I wanted to know. Do thanks to that I’ll be able to add the same component few times? (by saying “the same” i mean with the same name). I want to get a resault like with table columns generator where all added objects can be displayed in a table. Here I want to display all objects data not in a table but in layouts (something like creating the layouts dynamiclly), something like multiplying.

Sorry in advance for mistakes, english is not my native language :slight_smile: Cheers
[/s]

I’ve checked it! It works really well! Thank you, you’re awesome! :slight_smile:

Hi Daniel,

english isn’t my native language, too :wink:
But I think I’ve got your point right with my first answer, but “The code is documentation enough” didn’t work this time :stuck_out_tongue:
I was trying to explain that you should create a wrapper layout and add it to the “right_menu” slot of your CustomLayout. And when your Button is clicked you want to add the new movie VerticalLayout instances to the wrapper layout instead of the CustomLayout instead. This way you are able to add as many movie VerticalLayouts as you want.

So your component hierarchy will look like this:
CL (CustomLayout)
| – rightMenu (VerticalLayout)
| – movieLayout (VerticalLayout)
| – movieLayout (VerticalLayout)
| – …