In the last app menu (a.k.a “dynamic screen testing”) I have 2 buttons that dynamically add (i) a Button and (ii) a Fragment to my screen.
In order to remove one of the Fragment added to the screen (theBox), each fragment holds a linkButton (remove) that fires a CloseEvent to the main screen.
From here : big question mark. The container is “theBox”. I feel that I should do something like theBox.remove(something) but no way to find out what the something should be.
Any help, idea or suggestion is more than welcome.
Plan B is to make the Fragment not visible but I really would prefer to remove it…
The scrollBoxLayout component has some methods to remove child components:
remove(Component childComponent)
remove(Component... childComponents)
removeAll()
You can get child component using scrollBoxLayout#getComponentNN(String id) or scrollBoxLayout#getComponentNN(int index) methods. The fragment id is defined in @UiController annotation.
when I’m in the context of my screen and receive the event, I don’t how I can get the index of the fragment which sent the event … so I tried the solution with the Id.
I created 4 fragments (dynamically) and was surprised to see that they all had the same Id, which was “gantt_Basicgragment”. I thought an Id was meant to be unique …
Anyway, I implemented the following code in my Screen controller:
@Order(10)
@EventListener
public void onApplicationEvent(CloseEvent event) {
theBox.remove(theBox.getComponentNN("gantt_Basicgragment"));
}
and whatever the Basicgragment the Close button of I click on, always the same 2 first items are removed.
I’ve updated the code in GIT, I probably miss something. What is your opinion ?