I am all done adding what I need on createFieldByPropertyType, so the correct components are displayed on the form (ComboBox) for all my custom datatypes.
I have my form bound to a BeanItemContainer and all the controls have their values set to the corresponding value on the Bean y use to parse the types and insert the controls.
First question: How/where are default values are set on the controls, I need to set them for my ComboBoxes.
Second question: I am populating my ComboBox with the proper values on createField, by checking “type” against my custom classes… is this the proper way of doing it?
As additional info right now, when selecting a value on the ComboBoxes I get the following error:
com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: go.campaign.Beans.RateBean.(java.lang.String)
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:716)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:509)
From what I can tell this is all related to how values are set, is there a specific interfase I need to implement on my beans for the value to be set automatically?
How are you using the field factory? Most commonly you should let Form or Table automatically populate the fields with appropriate properties (and values). For various Select types, you only need to populate the available options (setContainerDataSource()), identifier types should there match to the property type of the Select.
Thanks for your reply, here are the methods I’ve modified on DefaultFieldFactory
public static Field createFieldByPropertyType(Class<?> type) {
// Null typed properties can not be edited
if (type == null) {
return null;
}
// Item field
if (Item.class.isAssignableFrom(type)) {
return new Form();
}
// Date field
if (Date.class.isAssignableFrom(type)) {
final DateField df = new DateField();
df.setResolution(DateField.RESOLUTION_DAY);
return df;
}
// Boolean field
if (Boolean.class.isAssignableFrom(type)) {
return new CheckBox();
}
//RateBean field
if(RateBean.class.isAssignableFrom(type)){
return new ComboBox();
}
//BalanceStatusEnum field
if(BalanceStatusEnum.class.isAssignableFrom(type)){
return new ComboBox();
}
return new TextField();
}
public Field createField(Item item, Object propertyId, Component uiContext) {
Class<?> type = item.getItemProperty(propertyId).getType();
Field field = createFieldByPropertyType(type);
field.setCaption(createCaptionByPropertyId(propertyId));
if(RateBean.class.isAssignableFrom(type)){
RateBean currentBean = new RateBean();
//get values and load options on ComboBox
currentBean = (RateBean) item.getItemProperty(propertyId).getValue();
for(int i=0; i< currentBean.getRateDetails().size();i++){
((ComboBox) field).addItem(currentBean.getRateDetails().get(i).getRateType().toString());
}
//Select proper option SELECTING NULL FOR NOW
((ComboBox) field).setValue(null);
}
if(BalanceStatusEnum.class.isAssignableFrom(type)){
BalanceStatusEnum currentBean;
//get values and load options on ComboBox
currentBean = (BalanceStatusEnum) item.getItemProperty(propertyId).getValue();
((ComboBox) field).addItem(currentBean.AVAILABLE);
((ComboBox) field).addItem(currentBean.CANCELLED);
((ComboBox) field).addItem(currentBean.DEPLEATED);
//Select proper option SELECTING NULL FOR NOW
((ComboBox) field).setValue(null);
}
return field;
}
The mods for the BalanceStatusEnum class work with no problem, not the case with my Bean Class as it is in itself a complex class with several properties and methods… the value to display for the caption and itemId to use on the combo are in the bean, but not exposed in any particular way, except for getters, along with other properties.