Im using a KeyValue Entity container for my table I have no entities
Looks good but i have no idea how to get the selected value.
DESCRIPTOR
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
caption="msg://newScreen.caption"
messagesPack="com.company.dropdownmap.web.screens">
<data>
<keyValueCollection id="fileKc">
<properties>
<property name="fileId" datatype="uuid"/>
<property name="fileName" datatype="string"/>
<property name="fileTypeId" datatype="uuid"/>
</properties>
</keyValueCollection>
</data>
<layout expand="tblFile">
<table id="tblFile" height="100%" width="100%" dataContainer="fileKc" editable="true">
<columns>
<column id="fileId"/>
<column id="fileName"/>
<column id="fileTypeId"/>
</columns>
</table>
<button id="btnSave" caption="Save"/>
</layout>
</window>
CONTROLLER
package com.company.dropdownmap.web.screens;
import com.haulmont.cuba.core.entity.KeyValueEntity;
import com.haulmont.cuba.gui.Notifications;
import com.haulmont.cuba.gui.UiComponents;
import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.LookupField;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.components.data.TableItems;
import com.haulmont.cuba.gui.model.InstanceContainer;
import com.haulmont.cuba.gui.model.KeyValueCollectionContainer;
import com.haulmont.cuba.gui.screen.*;
import javax.inject.Inject;
import java.util.*;
@UiController("dropdownmap_")
@UiDescriptor("new-screen.xml")
public class NewScreen extends Screen {
Map<String, UUID> fileTypes;
@Inject
private UiComponents uiComponents;
@Inject
private KeyValueCollectionContainer fileKc;
@Inject
private Notifications notifications;
@Inject
private Table tblFile;
@Subscribe
public void onInit(InitEvent event) {
fileTypes = new HashMap<>();
fileTypes.put("Type 1", UUID.randomUUID());
fileTypes.put("Type 2", UUID.randomUUID());
fileTypes.put("Type 3", UUID.randomUUID());
//INIT DUMMY DATA
KeyValueEntity file1 = new KeyValueEntity();
file1.setValue("fileId", UUID.randomUUID());
file1.setValue("fileName", "Contract");
KeyValueEntity file2 = new KeyValueEntity();
file2.setValue("fileId", UUID.randomUUID());
file2.setValue("fileName", "Performance Review");
List<KeyValueEntity> keyValueEntities = new ArrayList<>();
keyValueEntities.add(file1);
keyValueEntities.add(file2);
fileKc.setItems(keyValueEntities);
}
@Install(to = "tblFile.fileTypeId", subject = "columnGenerator")
private Component tblFileFileTypeIdColumnGenerator(Object object) {
LookupField lookupField = uiComponents.create(LookupField.class);
lookupField.setOptionsMap(fileTypes);
//THIS CLEARS THE SELECTION FROM THE DROPDOWN
/*lookupField.addValueChangeListener(valueChangeEvent -> { //valueChangevEvent.getValue does not exist
file.getItems().get(0).setValue("fileTypeId",//OBJECT ID);
});*/
return lookupField;
}
@Subscribe("btnSave")
public void onBtnSaveClick(Button.ClickEvent event) {
//I WANT TO SEE THE SELECTED VALUE ON THE DROPDOWN
//I SEE IT ON THE TABLE BUT THE VALUE IS NULL
//TableItems items = tblFile.getItems();
//Collection items1 = items.getItems();
notifications.create().withCaption(fileKc.getItems().get(0).getValue("fileTypeId").toString()).show();
}
/* Garbage
@Subscribe(id = "fileKc", target = Target.DATA_CONTAINER)
public void onFileKcItemChange(InstanceContainer.ItemChangeEvent<KeyValueEntity> event) {
fileKc.getItem(event.getItem()).setValue("fileTypeId",event.getItem().getValue("fileTypeId"));
}
*/
}
Thank you for the Help.