private void setAccordionSampleData(Accordion accordion, RadioButtonGroup radioGroup, Button button1, Button button2, Button button3) {
getContent().remove(accordion);
getContent().remove(radioGroup);
getContent().remove(button1);
getContent().remove(button2);
getContent().remove(button3);
List<MyOrder> actualMyOrders = getActualMyOrders();
User loggedUser = getLoggedUser();
Optional<MyOrder> any = actualMyOrders.stream()
.filter(myOrder -> myOrder.getUserName() == loggedUser.getName())
.filter(MyOrder::isActive)
.findAny();
if (getRestaurant() == null) description = new Span("Wybierz restaurację");
else description = new Span(getMeal(getRestaurant(), radioGroup).getDescription());
VerticalLayout descriptionLayout = new VerticalLayout(description);
descriptionLayout.setSpacing(true);
descriptionLayout.setPadding(true);
accordion.add("", descriptionLayout);
accordion.remove(descriptionLayout);
accordion.add("Opis potrawy - " + getMeal(getRestaurant(), radioGroup).getName(), descriptionLayout);
if (getRestaurant() == null) allergens = new Span("Wybierz restaurację");
else allergens = new Span(getMeal(getRestaurant(), radioGroup).getAllergens());
VerticalLayout allergensLayout = new VerticalLayout();
allergensLayout.setSpacing(true);
allergensLayout.setPadding(true);
allergensLayout.add(allergens);
accordion.add("",allergensLayout);
accordion.remove(allergensLayout);
accordion.add("Alergeny", allergensLayout);
```
if (getRestaurant() == null) nutritions = new Span("Wybierz restaurację");
else nutritions = new Span(getMeal(getRestaurant(), radioGroup).getNutritions());
VerticalLayout nutritionsLayout = new VerticalLayout();
nutritionsLayout.setSpacing(false);
nutritionsLayout.setPadding(true);
nutritionsLayout.add(nutritions);
accordion.add("", nutritionsLayout);
accordion.remove(nutritionsLayout);
accordion.add("Wartości odżywcze", nutritionsLayout);
getContent().add(radioGroup);
getContent().add(accordion);
if (any.isEmpty()) {
button1.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
getContent().add(button1);
}
else {
getContent().add(button2);
absent.addThemeVariants(ButtonVariant.LUMO_ERROR);
getContent().add(button3);
}```
Here’s my example class. Doesn’t have to be exactly like that, but it demonstrates how you can reuse components from accordion, instead of adding and removing them all the time.
https://gist.github.com/HerbertsVaadin/fdf6544c094efa1f481ef11a690083f5
OMG, solved
I will descript my solution
But don’t add code, now it’s truly unconventional… All the time I tried remove accordion from content but forget that the accordion bulid by java allergensLayout.add(allergens); accordion.add("Alergeny", allergensLayout);
When I make java accordion.remove(verticalLayout1);
it’s start working. Now have to go, I will refactor my code and describe it better cause you try help me a lot, thanks for now and I’ll back later
I still suggest you look at the example class I provided, so you could simplify your code, and so that you don’t have to worry about adding and removing components, but just updating the texts.
I read your code and in my code I extends Composite what’s gave me easy way to remove and add buttons depends if some one order pizza or not because after order its possible to re-order and cancle-order (Once button becomes to two butttons, and if cancle-order two buttons become one).
I also in other view I’ve possibility (under admin access) to runtime edit pizza names and description so that’s why I get all values from database, that’s why can’t create enums.
My main defect code why can’t remove accordion was that I try remove hole accordion using getContent.remove(accordion);
All code starts work as I expect after I use accordion.remove(accordionPanel);
and after that add new, updated accordionPanel. For now I stay in my solution because wan’t finish that project before weekend ends. Also have to say I work with vaadin just from a one week and learn Java form november last year and this is my first of ever solo project so many things are not clear for me. That’s why all the more so wan’t to Thank you for interest of my problem.
Now my main body of MenuView class looks like that ```java
getContent().add(radioGroup);
getContent().add(accordion);
getContent().add(order);
getContent().add(change);
getContent().add(absent);
setAccoriondSampleData(accordion, radioGroup);
orderClickListener(order);
changeClickListener(change);
absentClickListener(absent);
radioGroup.addValueChangeListener(event ->
setAccordionSampleDataAndRefresh(accordion, radioGroup, order, change, absent, descriptionLayout, allergensLayout, nutritionsLayout));
}```
private void setAccordionSampleDataAndRefresh(Accordion accordion, RadioButtonGroup radioGroup, Button button1, Button button2, Button button3, VerticalLayout verticalLayout1, VerticalLayout verticalLayout2, VerticalLayout verticalLayout3) {
accordion.remove(verticalLayout1);
accordion.remove(verticalLayout2);
accordion.remove(verticalLayout3);
getContent().remove(accordion);
getContent().remove(radioGroup);
getContent().remove(button1);
getContent().remove(button2);
getContent().remove(button3);
//
.. code omitted
//
getContent().add(radioGroup);
getContent().add(accordion);
if (any.isEmpty()) {
button1.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
getContent().add(button1);
}
else {
getContent().add(button2);
absent.addThemeVariants(ButtonVariant.LUMO_ERROR);
getContent().add(button3);
}
}```
That’s work as I want so I treat that as solved