如何在客户端编辑gwt requestfactory的ValueProxy的值?
我有 2 个模型:ContactGroup 和 Contact。 ContactGroup 包含许多联系人。
在页面中,我必须显示通信组中的组列表和联系人数量,如下所示:
- Group Foo (12 个联系人)
- Group Bar (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 实体中的字段。
在客户端,我使用了 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 列表时,我将该列表存储在 ArrayList 中以呈现到 CellTable。
我遇到的问题是:当我需要在客户端编辑组的名称时,我无法直接编辑 LightContactGroupProxy 对象。
- 因此,我必须将新名称发送到服务器以返回具有新名称的新 LightContactGroupProxy。这是无效的,因为我必须再次计算联系人数量(尽管我知道联系人数量不会改变)。
- 或者我必须将联系人数量和新名称发送到服务器,以使用新名称创建新的 LightContactGroupProxy。这不是我想要的,因为如果 LightContactGroupProxy 有许多其他字段,我必须发送许多字段。
我不知道GWT团队为什么要设计不可变代理。所以,请有人在 requestfactory 上有经验,请告诉我处理从服务器返回的 ValueProxy 的正确方法,以便我们可以使用它们来渲染和编辑?
谢谢
I have 2 models: ContactGroup and Contact. ContactGroup contains many Contacts.
In the page, I have to display a list of groups and number of contacts in the correspondence group like this:
- Group Foo (12 contacts)
- Group Bar (20 contacts)
So I at server side I used a 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; }
}
In this ContactGroupInfo, I added contactCount field which is not a field in ContactGroup entity.
And at client side, I used a 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);
}
So when server side returns to client side a list of LightContactGroupProxy, I stored that list a in ArrayList to render to a CellTable.
And here is the problem comes to me: when I need to edit the name of the group at client side, I can't edit the LightContactGroupProxy object directly.
- So I have to send the new name to server to return a new LightContactGroupProxy with the new name. This is not effective because I have to count contacts again (althought I know the number of contacts does not change).
- Or I have to send both the number of contacts and new name to server to create a new LightContactGroupProxy with the new name. This is not I want, because if LightContactGroupProxy has many other fields I have to send many fields.
I don't know why GWT teams designs the immutable proxy. So please, someone has experience on requestfactory please show me the correct way to handle ValueProxy returned from server so that we can use them to render and edit?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你应该尝试这样的事情:
无论如何,在这种情况下我不会使用
ValueProxy
,我会直接获取具有瞬态属性contactCount< 的
ContactGroup
实体/代码>。该属性可以是基元,也可以是ValueProxy
(如果您不希望每次请求ContactGroup
时都计算它)。Maybe you should try something like this :
Anyway, I wouldn't use
ValueProxy
in this case, I would directly get theContactGroup
entities with a transiant propertycontactCount
. The property could be a primitive, or aValueProxy
if you don't want it to be calculated every time aContactGroup
is requested.