GWT 2.4.0 RequestFactory多态性

时间:2011-10-02 09:55:12

标签: java polymorphism requestfactory gwt-2.4

GWT 2.4是否支持这种情况:

@Entity class MyBase {...}
@Entity class MyChild1 extends MyBase {...}
@Entity class MyChild2 extends MyBase {...}
...
@ProxyFor(MyBase.class) class MyBaseProxy extends EntityProxy {...}
@ProxyFor(MyChild1.class) class MyChild1Proxy extends MyBaseProxy {...}
@ProxyFor(MyChild2.class) class MyChild2Proxy extends MyBaseProxy {...}
...
@Service(ArticleBase.class)
public interface MyBaseRequest extends RequestContext {
    Request<MyBaseProxy> getStuff(); // MyChild1 here
}
...
Request<MyBaseProxy> getStuffRequest = request.getStuff();
getStuffRequest.fire(new Receiver<MyBaseProxy>() {
    @Override
    public void onSuccess(MyBaseProxy proxy) {
        button.setText(((MyChild1Proxy)proxy).getQwerty()); // HERE!
    }
});

问题是,我无法使其发挥作用。它要么不支持,要么我需要在某处添加一些魔法注释。当我使用具体类型时,一切正常,但如果我使用基础类型则不起作用。

您怎么看?

1 个答案:

答案 0 :(得分:10)

使用@ExtraTypes修正了它:

@Service(ArticleBase.class)
@ExtraTypes({MyChild1Proxy.class, MyChild2Proxy.class})
public interface MyBaseRequest extends RequestContext {
    Request<MyBaseProxy> getStuff(); // MyChild1 here
}