Hi, is it possible to dynamically add a fragment to a screen multiple times and have each fragment display a different data set? I have been able to add the fragment to the screen dynamically but can only get the fragments to display 1 address.
Example:
A customer can have multiple addresses and rather than displaying the addresses in a tabular format (as in the table of the screenshot) I want to display each address in a formatted block (like at the bottom of the screenshot).
I would recommend defining a method that sets an item to the fragment instance container, e.g.
@UiController("sales_OrderLineFragment")
@UiDescriptor("order-line-fragment.xml")
public class OrderLineFragment extends ScreenFragment {
@Inject
private InstanceContainer<OrderLine> orderLineDc;
public void setOrderLine(OrderLine orderLine) {
orderLineDc.setItem(orderLine);
}
}
So, in this case, you can use a fragment as follows:
private void drawFragments() {
for (OrderLine line : linesDc.getItems()) {
OrderLineFragment lineFragment = fragments.create(this, OrderLineFragment.class);
lineFragment.setOrderLine(line); // Set a specific item
lineFragment.init();
linesBox.add(lineFragment.getFragment());
}
}
Gleb, After implementing your suggestion I also had to change the fragment xml to have provider=“false” on the data collection once that was done everything worked as required.