I created a Vaadin Flow v22 Component wrapping the UI5 MultiComboBox Webcomponent:
@Tag("ui5-multi-combobox")
@NpmPackage(value = "@ui5/webcomponents", version = "^1.1.2")
@JsModule("@ui5/webcomponents/dist/MultiComboBox.js")
@JsModule("@ui5/webcomponents/dist/features/InputElementsFormSupport.js")
public class Ui5MultiComboBox extends Component implements HasComponents, HasLabel, HasSize {
…
public void setPlaceholder(String placeholder) {
this.getElement().setProperty("placeholder", placeholder);
}
…
@DomEvent("selection-change")
public static class SelectionChangeEvent extends ComponentEvent<Ui5MultiComboBox> {
public SelectionChangeEvent(Ui5MultiComboBox source, boolean fromClient,
@EventData("element.placeholder") String placeholder,
@EventData("event.bubbles") boolean bubbles,
@EventData("event.items") JsonArray itemsa) {
super(source, fromClient);
LOGGER.info("Ui5MultiComboBoxSelectionChangeEvent: placeholder=" + placeholder);
LOGGER.info("Ui5MultiComboBoxSelectionChangeEvent: bubbles=" + bubbles);
LOGGER.info("Ui5MultiComboBoxSelectionChangeEvent: itemsa=" + itemsa);
}
}
…
public Registration addSelectionChangeListener(ComponentEventListener<SelectionChangeEvent> listener) {
return addListener(SelectionChangeEvent.class, listener);
}
}
I then use the Vaadin Component in my Vaadin View:
…
Ui5MultiComboBox multiCombo1 = new Ui5MultiComboBox();
multiCombo1.setPlaceholder("Enter or pick items");
multiCombo1.addSelectionChangeListener(e -> {
LOGGER.info("View: Selection Changed Listener ...");
});
getContent().add(multiCombo1);
// add items:
for (ItemData d : data) {
Ui5MultiComboBoxItem multiComboItem = new Ui5MultiComboBoxItem();
multiComboItem.setText(d.text);
multiComboItem.setSelected(d.selected);
multiCombo1.add(multiComboItem);
}
I run my Application (in Crome) and it renders as expected.
When I remove one of the Ui5MultiComboBoxItem
, my Listener fires as expected.
The problem is that the Listener does not get access to the @EventData("event.items") JsonArray itemsa.
Console shows null for that itemsa
variable, while accessing more simple @EventData like "element.placeholder" or "event.bubbles" perfectly works:
Ui5MultiComboBoxSelectionChangeEvent: placeholder=Enter or pick items
Ui5MultiComboBoxSelectionChangeEvent: bubbles=true
Ui5MultiComboBoxSelectionChangeEvent: itemsa=null
View: Selection Changed Listener ...
I've also used:
@EventData("event.detail") JsonArray itemsa
@EventData("event.detail.items") JsonArray itemsa
@EventData("event.detail") JsonObject itemsa
@EventData("event.detail.items") JsonObject itemsa
@EventData("event.detail") String itemsa
@EventData("event.detail.items") String itemsa
@EventData("event.detail") Object itemsa
@EventData("event.detail.items") Object itemsa
but all these raise an error in Chrome Console:
(String) : Message JsonObject contained a dom node reference which should not be sent to the server and can cause a cyclic dependecy.
The typo in "dependecy
" might give a hint who is issuing that error message.
Here's the UI5 Web Component Description: MultiComboBox
Any help highly appreciated!