تسلسل GWT من فئة فرعية
-
01-10-2019 - |
سؤال
لدي خدمة RPC التي تُرجع كائنًا من نوع GameEvent يمتد من الحدث (الملخص). عندما أحصل على الكائن على جانب العميل ، يتم تعيين جميع الخصائص الموروثة من الحدث (EventID ، copyeventid ، gametimegmt) null
بينما على جانب الخادم ، فإن هذه الخصائص لها قيم.
public class GameEvent extends Event implements IsSerializable {
private String homeTeam;
private String awayTeam;
public GameEvent() {
}
}
// Annotation are from the twig-persist framework which should not
// impact the serialization process.
public abstract class Event implements IsSerializable {
@Key
protected String eventId;
@Index
protected String copyEventId;
protected Date gameTimeGMT;
protected Event() {
}
}
تحديث: أستخدم إطار عمل GWT-Platform (تطبيق MVP). فيما يلي دعوة إلى جانب عميل الخدمة. ال result.getGE()
يعيد كائن GameEvent ولكن مع null
الخصائص.
dispatcher.execute(
new GetFormattedEventAction(
id),
new AsyncCallback<GetFormattedEventResult>() {
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
@Override
public void onSuccess(
GetFormattedEventResult result) {
FormattedGameEvent formattedGameEvent = new FormattedGameEvent(
result.getGE());
}
});
معالج العمل:
public class GetFormattedEventActionHandler implements
ActionHandler<GetFormattedEventAction, GetFormattedEventResult> {
@Override
public GetFormattedEventResult execute(GetFormattedEventAction action,
ExecutionContext context) throws ActionException {
GameEvent gameEvent = null;
QueryResultIterator<GameEvent> rs = datastore.find().type(
GameEvent.class).addFilter("copyEventId", FilterOperator.EQUAL,
action.getEventId()).returnResultsNow();
if (rs.hasNext()) {
gameEvent = rs.next();
}
return new GetFormattedEventResult(gameEvent);
}
}
النتائج:
public class GetFormattedEventResult implements Result {
private GameEvent e;
@SuppressWarnings("unused")
private GetFormattedEventResult() {
}
public GetFormattedEventResult(GameEvent gameEvent) {
e = gameEvent;
}
public GameEvent getGE() {
return e;
}
}
المحلول
سأحاول أخذ طعنة.
تحقق .gwt.rpc
ملف تم إنشاؤه لكل واجهة خدمة). إذا لم يكن كذلك ، فقد تضطر إلى ذلك خدعة GWT في إضافته.
لا تنتمي إلى StackOverflow