Request Factory: Sending same proxy twice with different requests is causing changes to be dismissed

115 views
Skip to first unread message

Miroslav Genov

unread,
Aug 23, 2011, 6:31:24 AM8/23/11
to google-we...@googlegroups.com
I’m encountering an issue that is causing client side changes to be not sent when same entity proxy is sent for the second time to the server. My workflow is looking like:
  • load customer
  • edit customer in editor
  • preview customer changes
  • save customer
The problem is that the request sent to the server when save operation is invoked doesn’t send any customer changes that where made in the editor.

Loading our existing customer
customerRequest().findCustomerById(customerId).toReceiver(new Receiver() {
  public void onSuccess(CustomerProxy customerProxy) {

    CustomerRequest customerRequest = rf.customerRequest();

    customerRequest.previewCustomer(customerProxy).toReceiver(new Receiver() {

  public void onSuccess(String customerPreview) {

     display.renderCustomerPreview(customerPreview);

  }

    });

    editor.edit(customerRequest, customerProxy);

}
  }
}).fire();


Preview customer changes (response is a HTML generated content that is displayed in a HTML widget)

@UiHandler(“previewCustomer”)
public void onPreviewCustomer(ClickEvent event)  {
    RequestContext previewCustomer = editor.flush();
    previewCustomer.fire();
}

Save customer changes (here is the issue, the customer no longer contains changes that where set in the editor and the request that was sent to the server doesn’t contains any changed elements)
@UiHandler(“saveCustomer”)
public void onSaveCustomer(ClickEvent event)  {

CustomerRequest customerRequest = rf.customerRequest();

customerRequest.edit(customer);

customerRequest.persistCustomer(customer).toReceiver(new Receiver() {

  public void onSuccess(Void void) {

     

  }

}).fire();

}

In debug I can see the changes that are in the CustomerProxy before fire() of the requestContext is invoked, but the generated JSON that is sent to the server doesn’t contains any of these changes.

If I make a copy of the entity, the changes are sent, but the problem is that my CustomerProxy contains many inner object and I have to make a huge proxy copying, which is bad, cause when I add a new property to the proxy, I have to add a logic that copies it.

Any idea how this issue could be resolved ?

btw, The version of GWT which I’m using is GWT 2.4.0.RC1

Jens

unread,
Aug 23, 2011, 6:58:49 AM8/23/11
to google-we...@googlegroups.com
I am not quite sure as I have not used RF a lot but I think in onSaveCustomer() you can not create a new customer request, make the customer editable and then save it. By creating a new CustomerRequest you got a new (empty) RequestContext which does not know any of the changes you have done before. So you should reuse the RequestContext you have used to actually edit the customer..so basically the RequestContext you get from editor.flush() in your onPreviewCustomer() method. Thats the RequestContext that knows what changes have been done.

A different way is maybe to use the RequestContext.append() method to merge the RequestContext used to edit the customer with the new one that is created during save.

Hope this helps.

-- J.

Miroslav Genov

unread,
Aug 23, 2011, 8:11:19 AM8/23/11
to google-we...@googlegroups.com
I don't think that I could append RequestContext to another RequestContenxt which was already sent to the server. I thought that append() method is used for appending several RequestContext invocations into a single http round trip. I'm I right about this?

Thomas Broyer

unread,
Aug 23, 2011, 8:16:55 AM8/23/11
to google-we...@googlegroups.com
You're right. Actually, you cannot even append a RequestContext that has changes to another RequestContext. this is because "appending" actually means "sharing the same internal state", and there's no merging between states: "appending" a RequestContext to another kind-of creates a "mixin" of both.

Miroslav Genov

unread,
Aug 23, 2011, 8:23:44 AM8/23/11
to google-we...@googlegroups.com
Thomas, do you have any idea how this issue could be resolved? 

I'm still thinking that there should be some solution, cause load->edit->preview->save is a common workflow for document based application. 

Thomas Broyer

unread,
Aug 23, 2011, 8:26:16 AM8/23/11
to google-we...@googlegroups.com
The analysis is right: once your fire() a RequestContext, all changes made within its "context" are lost.

I'm not sure about it (would have to test it), but it might as easy as having an "echo" service method that you call in the "preview" context, so you get an immutable version of the proxy back, that you can then edit() in another context while keeping the changes made in the first one.

Miroslav Genov

unread,
Aug 23, 2011, 9:05:01 AM8/23/11
to google-we...@googlegroups.com
I made that change in my example app and I'm encountering the same issue. 

Here is the commit of my change, also you can checkout the project and run it in hosted mode to see how the things are going. 


Here is what I'm doing:

Change name of the customer to: "newname"
Hit preview button: Alert is displayed with "newname"
After that when I click the save button, then the server receives "customer1", which is the original name of the customer that comes from the database (in my case my In memory implementation). 

Miroslav Genov

unread,
Aug 23, 2011, 10:11:14 AM8/23/11
to google-we...@googlegroups.com
I just made a simple ant build script, so you could run the application directly, without any IDE setup. To run it you only have to set up your path to the GWT SDK and type:

ant devmode

Hope this will help. 

Jens

unread,
Aug 23, 2011, 10:43:34 AM8/23/11
to google-we...@googlegroups.com
Good to know
Reply all
Reply to author
Forward
0 new messages