2011-02-09 49 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