有没有一种方法来实现与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中正确实现。 –