Clear queue method invocations on RequestContext

43 views
Skip to first unread message

Alex Vakaloudis

unread,
Apr 27, 2012, 5:59:28 AM4/27/12
to google-we...@googlegroups.com
To perform a save  in a view I am using the RequestFactoryEditorDriver to flush any changes to a RequestContext and then I call save(the edited proxy).to(MyReceiver<Void>).fire();

MemberRequest s = (MemberRequest)editorDriver.flush();
MemberProxy sectorProxy = (MemberProxy)getProxy();
s.saveMember(sectorProxy).to(new MyReceiver<Void>()).fire();

MyReceiver has a onConstraintViolation method which displays violations generated in the server. I am using my own ServiceLayerDecorator.validate() to check for any business-related constraints.

To this point it works fine. However when after more than one  attempts the user finally "fixes" all violations and the entity reaches the service layer, the save method is invoked multiple times (as many attempts it took to pass validation). I understand that this is because the request context is queuing all method invocations and by calling onConstraintViolation. this queue is not cleared. As a result, when it passes validation there is a number of onvocations for saving which all then succeed in inserting to the database.

My question is how/where to clear the request context of any method invocations that have lead to the call of onConstraintViolation so the save to the service layer is called once only.

thanks in Advance
Alex

Florian Felberbauer

unread,
Jan 20, 2014, 3:32:02 AM1/20/14
to google-we...@googlegroups.com
Hello Alex,
it's been a while since you posted your problem but as I have the same problem now, I wanted to ask if you were able to fix it in the meantime. 
As you said, the problem is that both onConstraintViolation(...) and - after fixing the wrong data - even onSuccess(...) is fired multiple times because the request needs to stay the same (otherwise I get an error when trying to edit a proxy which has been edited by another request context). 

Thank you in advance! 
best regards, 
Flo 

Thomas Broyer

unread,
Jan 20, 2014, 10:24:36 AM1/20/14
to google-we...@googlegroups.com
You should queue the method invocation once only, at the time you receive the proxy to edit it, not at the time you want to fire() the prepared bacth-request.

Florian Felberbauer

unread,
Jan 20, 2014, 10:45:37 AM1/20/14
to google-we...@googlegroups.com
Hello all. 

The problem is that I need to call a domain method other dann persist, where I need to pass parameters. For that reason, I cannot prepare the request once (.to(new Receiver...)), but need to create it every time the user presses the save-button (otherwise, I do not get changes from the view to pass it to the server). 

What solved my problem was to save the proxy I get from the server and never edit it directly. Instead, I use something like: 
myRequest = rf.getMyRequest(); 
MyProxy myProxy = myRequest.edit(proxyFromServer); 

That way, my proxy from the server never gets edited by a request context directly and thus I can clone it as often as I need to.
But for the case that one only has to call persist().using(myProxy), setting up the request only once, with .to() instead of .fire() and fire it as often as needed, your approach is correct.  

Thanks anyway


2014/1/20 Thomas Broyer <t.br...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/nOsdq-gYwyE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.



--
DI Florian Felberbauer
Software Developer
Cenarion Information Systems GmbH
Mariahilfer Straße 176, 1150 Wien      
Handelsgericht Wien, FN 264084i

+43 1 522 1764 - 1180
       
http://www.cenarion.com
Reply all
Reply to author
Forward
0 new messages