1

I am trying to nest two request factory calls in each other. I retrieve a post object and in the success-method i use the same object again (just for testing purposes, I get the same behavior for other request like for example persisting).

The problem is: Only the first request reaches the server.

I don't get any error message. If I debug the code, everything works until the second request is fired. Nothing happens then. The method on the backend is not called, the frontend shows no error, even if I implement the "onFailure"-method for the receiver of the second request.

public class RequestFactoryFindTest extends GWTTestCase{

    /**
     * must refer to a valid module that sources this class.
     */
    public String getModuleName() {
        return "com.Test.MyTest";
    }

    public void test(){
        final ClientFactory clientFactory = GWT.create(ClientFactoryImpl.class);
        final MyRequestFactory requestFactory = clientFactory.getRequestFactory();
        final PostRequest request = requestFactory.postRequest();


        request.findPost(1l).fire(new Receiver<PostProxy>() {

            @Override
            public void onSuccess(PostProxy response) {


                final ClientFactory clientFactory = GWT.create(ClientFactoryImpl.class);
                final MyRequestFactory requestFactory = clientFactory.getRequestFactory();
                final PostRequest request = requestFactory.postRequest();

                System.out.println("outer success");

                request.findPost(1l).fire(new Receiver<PostProxy>() {

                    @Override
                    public void onSuccess(PostProxy response) {
                        System.out.println("inner success");

                    }

                });

            }
        });


    }
}

Can someone explain this?

Edit:

I tried a lot of stuff like to fire an event on the event bus, catch the event and do my inner request factory call there. But nothing worked. I think this is some Issue with the GWTTestcase in combination with RequestFactory. I also changed my code, so i use only one clientFactory.

4

2 回答 2

1

当您按照 Thomas Broyer 构建您的第二个客户工厂时,这可能是一个问题。您可能应该进入您的 ClientFactory.java 界面并在顶部添加单个客户端工厂实例。还要在 onSuccess(PostProxy response) 的顶部放置一个 GWT.log("ON SUCCESS") 以确保它到达那里。

public interface ClientFactory {

    public static final ClientFactory INSTANCE = GWT.create(ClientFactory.class); 
...

然后你可以像下面这样简单地做一些事情

    final PostRequest request = ClientFactory.INSTANCE.getRequestFactory().postRequest();
于 2013-07-19T13:54:35.833 回答
1

尝试在第一个 onSuccess 方法中创建一个事件。处理您的事件后,您可以向服务器发送另一个请求。查看如何使用 GWT EventBus来使用事件总线。

Thomas Broyer 的说法也是正确的。您应该只使用一个 RequestFactory 和一个 ClientFactory!

于 2013-07-19T08:01:07.010 回答