ContactGroup と Contact の 2 つのモデルがあります。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 に、ContactGroup エンティティのフィールドではない contactCount フィールドを追加しました。
クライアント側では、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 チームが不変プロキシを設計する理由がわかりません。ですから、リクエストファクトリーの経験がある人は、サーバーから返された ValueProxy を処理してレンダリングと編集に使用できるようにする正しい方法を教えてください。
ありがとうございました