GWT RequestFactory 返回空对象

发布于 2024-12-05 11:47:30 字数 2382 浏览 0 评论 0原文

我正在尝试使用 GWT RequestFactory(目前)做一些非常简单的事情并返回一个对象列表,每个对象包含一些数据和另一个对象。我似乎无法获取其他对象 - 相反,我总是得到 null。

我的代码看起来像这样...

我有一些 UserMessage 对象,每个对象都包含一个 Message 对象。

UserMessage

@Entity
public class UserMessage implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  private Long id;

  @Version
  private Integer version = 0;

  @ManyToOne
  @JoinColumn(name = "messageId")
  private Message message;

  private String user;

  private int priority;

  private boolean read;

  private Date expiry;

  private boolean sent;

  ... getter/setters etc

Message

  @Entity(name = "UUMessage")
  public class Message implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  private Long id;

  @Version
  private Integer version = 0;

  private String title;

  private String mimeType;

  private String message;

  private Date received;

  private String fromUser;

  public Message() {

  }

  ... getter/setters etc

每个都有自己的代理类

UserMessageProxy

@ProxyFor(value = UserMessage.class, locator = UserMessageLocator.class)
public interface UserMessageProxy extends EntityProxy {

  Long getId();

  void setId(Long id);

  MessageProxy getMessage();

  void setMessage(MessageProxy message);

  String getUser();
}

MessageProxy

@ProxyFor(value = Message.class, locator = MessageLocator.class)
public interface MessageProxy extends EntityProxy {

Long getId();

void setId(Long id);

String getTitle();

void setTitle(String title);

}

我有一个工厂和一个上下文

@Service(value = CentralNotificationService.class, locator = CentralNotificationServiceLocator.class)
public interface CnsRequestContext extends RequestContext {

  Request<List<UserMessageProxy>> getMessagesForUser(String user, int start, int length);

}

当我调用时getMessagesForUser(...) 在客户端上,我的服务器端服务代码被调用,检索数据库中的条目,并且我得到返回给客户端的 UserMessageProxy 列表。不幸的是,对其中任何一个调用 getMessage() 都会返回 null,我不知道为什么。

我没有收到任何错误或警告。在服务器端,当 RequestFactory 代码调用我的服务类时,我可以“看到”UserMessage 确实包含 Message 对象。

为什么我的对象为空?有什么条件是我不满足的吗?

GWT 2.4 BTW(但 2.3 也有问题)

I am trying to use GWTs RequestFactory to (at the moment) do something very simple and return a list of objects each containing some data and another object. I don't seem to be able to get my other object - instead I always get null.

My code looks something like this...

I have some UserMessage objects which each include a Message object.

UserMessage

@Entity
public class UserMessage implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  private Long id;

  @Version
  private Integer version = 0;

  @ManyToOne
  @JoinColumn(name = "messageId")
  private Message message;

  private String user;

  private int priority;

  private boolean read;

  private Date expiry;

  private boolean sent;

  ... getter/setters etc

Message

  @Entity(name = "UUMessage")
  public class Message implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  private Long id;

  @Version
  private Integer version = 0;

  private String title;

  private String mimeType;

  private String message;

  private Date received;

  private String fromUser;

  public Message() {

  }

  ... getter/setters etc

each with their own proxy classes

UserMessageProxy

@ProxyFor(value = UserMessage.class, locator = UserMessageLocator.class)
public interface UserMessageProxy extends EntityProxy {

  Long getId();

  void setId(Long id);

  MessageProxy getMessage();

  void setMessage(MessageProxy message);

  String getUser();
}

MessageProxy

@ProxyFor(value = Message.class, locator = MessageLocator.class)
public interface MessageProxy extends EntityProxy {

Long getId();

void setId(Long id);

String getTitle();

void setTitle(String title);

}

I have a factory and a context

@Service(value = CentralNotificationService.class, locator = CentralNotificationServiceLocator.class)
public interface CnsRequestContext extends RequestContext {

  Request<List<UserMessageProxy>> getMessagesForUser(String user, int start, int length);

}

When I call getMessagesForUser(...) on the client my server side service code gets called, the entries in the database are retrieved and I get a list of UserMessageProxy returned to the client. Unfortunately calling getMessage() on any of these returns null and I can't work out why.

I am not getting any errors or warnings. On the server side I can "see" that the UserMessage does contain the Message objects when the RequestFactory code calls into my service classes.

Why are my objects null? Are there any conditions I am not satisfying?

GWT 2.4 BTW (but also had problems with 2.3)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-12-12 11:47:30

您的代码可能缺少 .with("message")

查询服务器时,RequestFactory 不会自动填充对象图中的关系。为此,请在请求上使用 with() 方法并将相关属性名称指定为 String
[…]
还需要使用 with() 方法来检索具有扩展 ValueProxy 类型的任何属性。 with() 方法接受多个 String 参数,因此您可以一次指定多个属性名称。要指定嵌套属性,请使用点表示法。

来源 http://code.google .com/webtoolkit/doc/latest/DevGuideRequestFactory.html#relationships

Your code is probably missing a .with("message"):

When querying the server, RequestFactory does not automatically populate relations in the object graph. To do this, use the with() method on a request and specify the related property name as a String
[…]
It is also necessary to use the with() method to retrieve any properties with types extending ValueProxy. The with() method takes multiple String arguments, so you can specify multiple property names at once. To specify nested properties, use dot notation.

Source: http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html#relationships

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文