2011-02-09 48 views

回答

7

在GWT 2.1.1中,Id和Version属性可以是RequestFactory知道如何传输的任何类型。基本上,任何原始类型(int),盒装类型(Integer)或任何具有关联代理类型的对象。您不必自己将复合标识减少为一个字符串; RF管道可以通过使用实体类型密钥的持久性ID或值类型密钥的序列化状态来自动处理复合密钥。

使用先前发布的例子:

interface Location { 
    public String getDepartment(); 
    public String getDesk(); 
} 

interface Employee { 
    public Location getId(); 
    public int getVersion(); 
} 

@ProxyFor(Location.class) 
interface LocationProxy extends ValueProxy { 
    // ValueProxy means no requirement for getId()/getVersion() 
    String getDepartment(); 
    String getDesk(); 
} 
@ProxyFor(Employee.class) 
interface EmployeeProxy extends EntityProxy { 
    // Use a composite type as an id key 
    LocationProxy getId(); 
    // Version could also be a complex type 
    int getVersion(); 
} 

如果不能降低身份对域类型的单个getId()属性,你可以使用Locator提供一个外部定义ID和版本属性。例如:

@ProxyFor(value = Employee.class, locator = EmployeeLocator.class) 
interface EmployeeProxy {.....} 

class EmployeeLocator extends Locator<Employee, String> { 
    // There are several other methods to implement, too 
    String getId(Employee domainObject) { return domainObject.getDepartment() + " " + domainObject.getDesk(); } 
} 

从提问联的DevGuide是有点过时相对于对 RequestFactory changes in 2.1.1

+1

应当mentionned该复合ID *必须*被映射为一个ValueProxy(LocationProxy在代理必须暴露在代理中的某处(例如,当您从GWT.create()d RequestFactory开始的接口和方法行走时可以访问;在上面的示例代码中,它可以从EmployeeProxy上的getId访问)。 – 2011-02-14 22:45:29