我有 2 个模型:ContactGroup 和 Contact。ContactGroup 包含许多联系人。
在页面中,我必须显示通信组中的组列表和联系人数量,如下所示:
- Foo 组(12 个联系人)
- 群组栏(20 个联系人)
所以我在服务器端使用了 DTO ContactGroupInfo:
public class ContactGroupInfo {
private Integer contactCount;
private Long id;
private String name;
public Integer getContactCount() { return this.contactCount; }
public Long getId() { return this.id; }
public String getName() { return this.name; }
public void setContactCount(Integer count) { this.contactCount = count; }
public void setId(Long id) { this.id = id; }
public void setName(String name) { this.name = name; }
}
在此 ContactGroupInfo 中,我添加了contactCount 字段,该字段不是 ContactGroup entity 中的字段。
在客户端,我使用了 ValueProxy:
@ProxyFor(value = ContactGroupInfo.class, locator = ContactGroupService.class)
public interface LightContactGroupProxy extends ValueProxy {
Integer getContactCount();
Long getId();
String getName();
void setContactCount(Integer count);
void setId(Long id);
void setName(String name);
}
因此,当服务器端向客户端返回 LightContactGroupProxy 列表时,我将该列表 a 存储在 ArrayList 中以呈现给 CellTable。
这里是我遇到的问题:当我需要在客户端编辑组的名称时,我无法直接编辑 LightContactGroupProxy 对象。
- 所以我必须将新名称发送到服务器以返回具有新名称的新 LightContactGroupProxy。这无效,因为我必须再次计算联系人(虽然我知道联系人的数量不会改变)。
- 或者我必须将联系人数量和新名称都发送到服务器,以使用新名称创建一个新的 LightContactGroupProxy。这不是我想要的,因为如果 LightContactGroupProxy 有很多其他字段,我必须发送很多字段。
我不知道 GWT 团队为什么要设计不可变代理。所以拜托,有人有requestfactory的经验,请告诉我处理从服务器返回的ValueProxy的正确方法,以便我们可以使用它们来渲染和编辑?
谢谢