【发布时间】:2014-01-09 20:54:46
【问题描述】:
有没有办法使用与 propertyId 相关的特定字段来实现 TableFactory 接口? 我只得到一种类型的字段,因为我对所有表都使用了一个通用类,并且我缺少 CheckBox 布尔值(groovy 代码):
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 个)提供这个 null 表示,我想使用这个类作为每个表的默认工厂,并像以前一样连接它:
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())
【问题讨论】: