有沒有一種方法來實現與PropertyId相關的特定字段的TableFactory接口? 我只得到一個類型的字段,因爲我使用的是通用類爲我所有的表,和我丟失的CheckBox布爾值(Groovy代碼):Vaadin 7:TableFieldFactory
class DefaultTableFieldFactory implements TableFieldFactory {
@Override
public Field<?> createField(Container container, Object itemId, Object propertyId, Component component) {
TextField t = new TextField()
switch(propertyId) {
case "firstname": t.setNullRepresentation("");
case "lastname": t.setNullRepresentation("");
case "mobile": t.setNullRepresentation("");
case "tel": t.setNullRepresentation("");
case "email": t.setNullRepresentation("");
default: break;
}
t.setWidth("95px")
return t
}
}
,所以我需要使用上面這個類其中包含DefaultTableFieldfactory,以便在整個應用程序中將null表達式設置爲「」(而不是「null」)。
我們的目標是在一個地方爲我的自定義組件(超過30個)提供這種空表示,我想將這個類用作每個表的默認工廠,並像以前那樣連接它:
def contacts = (Grails.get(FundService)).getAllContacts(fundId)
def cContainer = new BeanItemContainer<Contact>(Contact.class,contacts)
def t = new Table()
t.containerDataSource = cContainer
t.setTableFieldFactory(new DefaultTableFieldFactory())
謝謝,但我已經知道什麼是DefaultTableFactory,因爲我在我的代碼中實現它。此處的目標是提供此工廠以在單個工廠中處理不同類型的字段,以便將此模式應用於表的容器數據源(請參閱上面修改的代碼) –
@ludo_rj然後查看createFieldByType()方法Vaadin提供的DefaultFieldFactory類在適當時返回CheckBox。 – nexus
是的,這就是我正在尋找的:)因爲DefaultFieldFactory.createFieldByPropertyType是靜態的,所以它不能被覆蓋,所以它需要額外的代碼才能在TableFieldFactory中正確實現。 –