简体   繁体   English

GWT RequestFactory返回一个空对象

[英]GWT RequestFactory returns a null object

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. 我正在尝试使用GWT的RequestFactory(目前)做一些非常简单的事情,并返回一个对象列表,每个对象包含一些数据和另一个对象。 I don't seem to be able to get my other object - instead I always get null. 我似乎无法获取我的另一个对象-相反,我总是得到null。

My code looks something like this... 我的代码看起来像这样...

I have some UserMessage objects which each include a Message object. 我有一些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

each with their own proxy classes 每个都有自己的代理类

UserMessageProxy 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. 当我在客户端上调用getMessagesForUser(...)时,我的服务器端服务代码被调用,数据库中的条目被检索,并且我获得了返回给客户端的UserMessageProxy的列表。 Unfortunately calling getMessage() on any of these returns null and I can't work out why. 不幸的是,在这些方法中的任何一个上调用getMessage()都会返回null,我无法弄清楚为什么。

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. 在服务器端,当RequestFactory代码调用我的服务类时,我可以“看到” UserMessage确实包含Message对象。

Why are my objects null? 为什么我的对象为空? Are there any conditions I am not satisfying? 我有什么不满意的条件吗?

GWT 2.4 BTW (but also had problems with 2.3) GWT 2.4 BTW(但在2.3中也有问题)

Your code is probably missing a .with("message") : 您的代码可能缺少.with("message")

When querying the server, RequestFactory does not automatically populate relations in the object graph. 查询服务器时,RequestFactory不会自动在对象图中填充关系。 To do this, use the with() method on a request and specify the related property name as a String 为此,请在请求上使用with()方法,并将相关属性名称指定为String
[…] […]
It is also necessary to use the with() method to retrieve any properties with types extending ValueProxy. 还必须使用with()方法来检索具有扩展ValueProxy类型的任何属性。 The with() method takes multiple String arguments, so you can specify multiple property names at once. with()方法采用多个String参数,因此您可以一次指定多个属性名称。 To specify nested properties, use dot notation. 要指定嵌套属性,请使用点表示法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM