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.

jan
  • 3,923
  • 9
  • 38
  • 78
  • 4
    I can't explain it, but I can tell you that you should only create a single `MyRequestFactory` for your whole app. You should probably also do this for the `ClientFactory`. – Thomas Broyer Jul 11 '13 at 10:01
  • Tried it, but did not change anything – jan Jul 23 '13 at 20:03

2 Answers2

1

Try to create an event in the first onSuccess method. When your event is handled, you could send another request to the server. Check out How to use the GWT EventBus to use the eventbus.

Thomas Broyer statement is also right. You should only use one RequestFactory and one ClientFactory!

Community
  • 1
  • 1
Charmin
  • 711
  • 20
  • 30
1

This may be a problem when you are constructing your second client factory as per Thomas Broyer. You should probably go into your ClientFactory.java interface and at the top add the the single client factory instance. Also put a GWT.log("ON SUCCESS") at the top of your onSuccess(PostProxy response) to make sure it is getting there.

public interface ClientFactory {

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

Then you can simple do somehting like the following

    final PostRequest request = ClientFactory.INSTANCE.getRequestFactory().postRequest();
Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65