GWT RequestFactory 返回空对象
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码可能缺少
.with("message")
:— 来源 http://code.google .com/webtoolkit/doc/latest/DevGuideRequestFactory.html#relationships
Your code is probably missing a
.with("message")
:— Source: http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html#relationships