Hi all,
I’m trying to put a Select component when editing my Table using the TableFieldFactory but apparently the function createField() can only generate a DateField, a CheckBox, a Form or a TextField.
Any idea how I can do this?
Thx
Hi all,
I’m trying to put a Select component when editing my Table using the TableFieldFactory but apparently the function createField() can only generate a DateField, a CheckBox, a Form or a TextField.
Any idea how I can do this?
Thx
The DefaultTableFieldFactory only creates fields of the types you mentioned, but nothing stops you from extending it, overriding either createField() or createFieldByPropertyType() and checking the property name or type to create and initialize (set container, immediate, item caption property, …) a ComboBox. Then use an instance of that field factory for your table. See e.g.
this book chapter
for more information on field factories and an example.
Note that the value for the field is set automatically, outside the field factory. The field factory should create the field and e.g. set its container or do other initialization, but not set the value.
Oups sorry, I didn’t notice it was for a table
Normally you should be able to use a Select, I’m using it in my Table.
I use a Table.ColumnGenerator to achieve that
Ok thanks for your help
it’s working fine in the case where my select is a list of String
public class MyTableFieldFactory implements TableFieldFactory {
@Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
if("typeDate".equals(propertyId)){
Select select = new Select();
select.addItem("Berlin");
select.addItem("Helsinki");
select.addItem("London");
select.addItem("New York");
select.addItem("Turku");
select.setImmediate(true);
select.setReadOnly(false);
return select;
} else {
return null;
}
}
but if I use a list of object, this doesn’t work…
public class MyTableFieldFactory implements TableFieldFactory {
@Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
if("typeDate".equals(propertyId)){
Select select = new Select();
BeanItemContainer<Codetaxpm> containerCodeTaxPm = new BeanItemContainer<Codetaxpm>(Codetaxpm.class);
Map<String, Codetaxpm> map = SessionHandler.getLibelle("COD_TYP_DAT");
if(map!=null && map.size()>0){
for(String mapKey : map.keySet()){
containerCodeTaxPm.addItem(map.get(mapKey));
}
}
select.setContainerDataSource(containerCodeTaxPm);
select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
select.setItemCaptionPropertyId("lib");
return select;
} else
return null;
}
}
I even don’t have the select box…
I am having the same problem. My Selectbox works fine in the table when using Strings, but not when using objects. Is there a workaround? Or am I doing something wrong?