質問

I need your help with the gwt requestfactory

considering following scenario:
I get an existing entity (let's say a invoice) from the server:

InvoiceEntityProxy invoice = request1.getInvoice();

I want to make some changes, so I edit it with a new request:

InvoiceEntityProxy editableInvoice = request2.edit(invoice);
//make some changes to editableInvoice

Now I send the changes made with the second request to the server, to create a preview:

request2.createPreview(editableInvoice);

When the request is sent, the invoice proxy is frozen and I re-enable editing by assigning the proxy to a new request:

editableInvoice = request3.edit(editableInvoice);

If everything is okay, i want to update the proxy and send it to the server, using the latest request:

request3.update(editableInvoice);

But the changes never arrive on the server, because the latest request (request3) doesn't know anything about the changes made to the proxy assigned to the request2.

I thought about following solutions:

  1. I could redo the changes on the latest proxy. But for that, I've to iterate over all attributes and set them again (not very friendly solution, because I've to adjust the method each time I add some attributes to the proxy)
  2. Another approach would be to send the proyx without an id to the server and send the id as second parameter of the update-method. But this would be a shame, because not only the deltas would be sent to the server (which is one of the greate features of the requestFactory).

So what is the best and most common practice to let the request3 know about the changes already made to the proxy, when it was assigned to another request.

役に立ちましたか?

解決 2

Nice! I found the solution for my problem.

I still have an instance of the original proxy, because the edit() method of the context always return a new instance of the proxy. So I save the original proxy before sending any request.

After each successful request, I re-enable editing the proxy by call the edit method again:

editableInvoice = request3.edit(editableInvoice);

Now the crux: I can set the original proxy of a proxy, which is used to consider if it changed and what changed. This is done by using AutoBean and set the PARENT_OBJECT Tag like this:

AutoBean<InvoiceEntityProxy> editableInvoiceBean = AutoBeanUtils.getAutoBean(editableInvoice);
AutoBean<InvoiceEntityProxy> originalInvoiceBean = AutoBeanUtils.getAutoBean(originalInvoice);

editableInvoiceBean.setTag(Constants.PARENT_OBJECT, originalInvoiceBean);

On the next request all changed properties are send to the server again.

Thank you for your help and thank you for the hint with the AutoBean @Zied Hamdi

他のヒント

You simply forget to call fire(). Example

request2.createPreview(editableInvoice).fire();

Bear in mind that if the following request depend on the result of the previous one, you should put your code in the OnSuccess methode because the request is asynchronous

It's also possible to append multiple requests

EDIT

It important to use the same request for the edit and fire operations. So replace this line

request.update(editableInvoice);

with

request3.update(editableInvoice);

You also can use AutoBeans to duplicate the object before you start changing it. You can keep the original one untouched then request.edit() it and apply changes (introspection like changes) from the "dirty" object.

You'll maybe have to do some research on how to handle EntityProxies since they are "special AutoBeans" : I had to use special utility objects to serialize them to json (available in GWT). So there might be some special handling in doing a deep copy too.

There is an issue maybe with GWT keeping only one version of each EntityProxy (I never checked if it is global or only in the context of a request)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top