Re: RequestFactory - Send error to client
Hello, i have the same problem and the same interrogation (intentional or not ?) If you look on the RF doc, all code examples use Request to fire(), but all the real samples (DynaTableRF, Expenses) I've studied use RequestContext to fire() instance request. And is there any other differences between the two "fires" ? Any RF developers around ? :) Anthony. On 16 nov, 16:27, Dain Kaplan wrote: > I dug around a bit and discovered why the onFailure() handler was not being > called. The DynaTableRf sample that ships with GWT 2.1 uses the new Editor > framework. In the PersonEditorWorkflow.java class it initializes the editor > and keeps a copy of the RequestContext as follows: > > PersonRequest context =requestFactory.personRequest(); > context.persist().using(person); > > When the user clicks the "Save" button, the onSave() click handler gets > called, which basically does: > > context.fire(new Receiver() { > @Override > public void onSuccess(Void response) { > dialog.hide(); > } > > @Override > public void onViolation(Set errors) { > dialog.setText("Errors detected on the server"); > editorDriver.setViolations(errors); > } > }); > > For dealing with successes and violations, that works fine. The problem > happens when you want to deal with exceptions thrown on the server. The > RequestContext and Request objects seem to have their own Receiver() > instances, but only the Receiver instance for the Request (and NOT the > RequestContext) gets parsed for server-side exceptions (see > com.google.gwt.requestfactory.client.impl.AbstractRequest.handleResponseText() > for the error parsing code, and AbstractRequestContext.doFire() for > RequestContext code that ignores any errors). To briefly show what's going > on, below is a snippet from the TransportReceiver that gets created in the > AbstractRequestContext.doFire() method for handling the request: > > public void onTransportSuccess(String payload) { > try { > // TODO: chained methods > assert invocations.size() == 1; > invocations.get(0).handleResponseText(payload); > > if (receiver != null) { > if (errors.isEmpty()) { > receiver.onSuccess(null); > // After success, shut down the context > editedProxies.clear(); > invocations.clear(); > returnedProxies.clear(); > } else { > receiver.onViolation(errors); > } > } > } finally { > postRequestCleanup(); > } > } > > What winds up happening is that if the payload contains errors, they get > processed in the handleResponseText() method call, but only if the request > instance has a Receiver set. The code below that does not handle errors at > all, so even on error the onSuccess() method of your receiver gets called. > > Is such behavior intentional? > > The workaround is to set the Request's Receiver instance and call > context.fire() instead, but still leaves the DynaTableRf sample a bit > misleading. > > DK > > On Nov 16, 2010, at 4:43 PM, DK wrote: > > > I've encountered the same problem. Intuition says that throwing an > > error should trigger the onFailure() method, not the onSuccess() > > method with a SEVERE logging the exception. Is this a known bug? > > > On Nov 6, 5:03 am, Henrique F M wrote: > >> Hi there, > > >> I didn't find the solution to this anywhere, so I'm creating this new > >> discussion. > > >> I want to be able to send errors from myRequestFactoryto the client. > >> Let me give an example: let's say my app is a simple Person CRUD. My > >> Person class has a String name attribute and I don't want to have more > >> than two Persons with the same name. So i was thinking something like > >> this: > > >> --RequestFactoryServer Implementation > >> public static Person createNewPerson(String name){ > >> > >> if( isThereAnotherPersonWithThisName(name) ){ > > >> //do something HERE > > >> }else{ > >> pm.makePersistent(person); > >> } > >> ... > > >> } > > >> -- Client --- > >> ().fire( > >> new Receiver() { > >> @Override > >> public void onSuccess(Person person) { > >> Window.alert("OK!"); > >> //do stuff > >> } > >> @Override > >> public void onFailure(ServerFailure error) { > >> Window.alert("Fail!"); > >> Window.alert(error.getMessage()); > >> //do stuff > >> } > >> }); > > >> > >> I don't know what I have to do on HERE to make my Receiver go to > >> onFailure. I've tried to throw Exceptions, RequestException, but it > >> only make my server log the error and the response never arrives to > >> the client. > >> Am I missing something here?
Re: RequestFactory - Send error to client
I dug around a bit and discovered why the onFailure() handler was not being called. The DynaTableRf sample that ships with GWT 2.1 uses the new Editor framework. In the PersonEditorWorkflow.java class it initializes the editor and keeps a copy of the RequestContext as follows: PersonRequest context = requestFactory.personRequest(); context.persist().using(person); When the user clicks the "Save" button, the onSave() click handler gets called, which basically does: context.fire(new Receiver() { @Override public void onSuccess(Void response) { dialog.hide(); } @Override public void onViolation(Set errors) { dialog.setText("Errors detected on the server"); editorDriver.setViolations(errors); } }); For dealing with successes and violations, that works fine. The problem happens when you want to deal with exceptions thrown on the server. The RequestContext and Request objects seem to have their own Receiver() instances, but only the Receiver instance for the Request (and NOT the RequestContext) gets parsed for server-side exceptions (see com.google.gwt.requestfactory.client.impl.AbstractRequest.handleResponseText() for the error parsing code, and AbstractRequestContext.doFire() for RequestContext code that ignores any errors). To briefly show what's going on, below is a snippet from the TransportReceiver that gets created in the AbstractRequestContext.doFire() method for handling the request: public void onTransportSuccess(String payload) { try { // TODO: chained methods assert invocations.size() == 1; invocations.get(0).handleResponseText(payload); if (receiver != null) { if (errors.isEmpty()) { receiver.onSuccess(null); // After success, shut down the context editedProxies.clear(); invocations.clear(); returnedProxies.clear(); } else { receiver.onViolation(errors); } } } finally { postRequestCleanup(); } } What winds up happening is that if the payload contains errors, they get processed in the handleResponseText() method call, but only if the request instance has a Receiver set. The code below that does not handle errors at all, so even on error the onSuccess() method of your receiver gets called. Is such behavior intentional? The workaround is to set the Request's Receiver instance and call context.fire() instead, but still leaves the DynaTableRf sample a bit misleading. DK On Nov 16, 2010, at 4:43 PM, DK wrote: > I've encountered the same problem. Intuition says that throwing an > error should trigger the onFailure() method, not the onSuccess() > method with a SEVERE logging the exception. Is this a known bug? > > On Nov 6, 5:03 am, Henrique F M wrote: >> Hi there, >> >> I didn't find the solution to this anywhere, so I'm creating this new >> discussion. >> >> I want to be able to send errors from my RequestFactory to the client. >> Let me give an example: let's say my app is a simple Person CRUD. My >> Person class has a String name attribute and I don't want to have more >> than two Persons with the same name. So i was thinking something like >> this: >> >> -- RequestFactory Server Implementation >> public static Person createNewPerson(String name){ >> >> if( isThereAnotherPersonWithThisName(name) ){ >> >> //do something HERE >> >> }else{ >> pm.makePersistent(person); >> } >> ... >> >> } >> >> -- Client --- >> ().fire( >> new Receiver() { >> @Override >> public void onSuccess(Person person) { >> Window.alert("OK!"); >> //do stuff >> } >> @Override >> public void onFailure(ServerFailure error) { >> Window.alert("Fail!"); >> Window.alert(error.getMessage()); >> //do stuff >> } >> }); >> >> >> I don't know what I have to do on HERE to make my Receiver go to >> onFailure. I've tried to throw Exceptions, RequestException, but it >> only make my server log the error and the response never arrives to >> the client. >> Am I missing something here? What would you suggest? >> >> Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to google-web-tool...@googlegroups.com. > To unsubscribe from this group, send email to > google-web-toolkit+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool.
Re: RequestFactory - Send error to client
I've encountered the same problem. Intuition says that throwing an error should trigger the onFailure() method, not the onSuccess() method with a SEVERE logging the exception. Is this a known bug? On Nov 6, 5:03 am, Henrique F M wrote: > Hi there, > > I didn't find the solution to this anywhere, so I'm creating this new > discussion. > > I want to be able to send errors from my RequestFactory to the client. > Let me give an example: let's say my app is a simple Person CRUD. My > Person class has a String name attribute and I don't want to have more > than two Persons with the same name. So i was thinking something like > this: > > -- RequestFactory Server Implementation > public static Person createNewPerson(String name){ > > if( isThereAnotherPersonWithThisName(name) ){ > > //do something HERE > > }else{ > pm.makePersistent(person); > } > ... > > } > > -- Client --- > ().fire( > new Receiver() { > @Override > public void onSuccess(Person person) { > Window.alert("OK!"); > //do stuff > } > @Override > public void onFailure(ServerFailure error) { > Window.alert("Fail!"); > Window.alert(error.getMessage()); > //do stuff > } > }); > > > I don't know what I have to do on HERE to make my Receiver go to > onFailure. I've tried to throw Exceptions, RequestException, but it > only make my server log the error and the response never arrives to > the client. > Am I missing something here? What would you suggest? > > Thanks -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
RequestFactory - Send error to client
Hi there, I didn't find the solution to this anywhere, so I'm creating this new discussion. I want to be able to send errors from my RequestFactory to the client. Let me give an example: let's say my app is a simple Person CRUD. My Person class has a String name attribute and I don't want to have more than two Persons with the same name. So i was thinking something like this: -- RequestFactory Server Implementation public static Person createNewPerson(String name){ if( isThereAnotherPersonWithThisName(name) ){ //do something HERE }else{ pm.makePersistent(person); } ... } -- Client --- ().fire( new Receiver() { @Override public void onSuccess(Person person) { Window.alert("OK!"); //do stuff } @Override public void onFailure(ServerFailure error) { Window.alert("Fail!"); Window.alert(error.getMessage()); //do stuff } }); I don't know what I have to do on HERE to make my Receiver go to onFailure. I've tried to throw Exceptions, RequestException, but it only make my server log the error and the response never arrives to the client. Am I missing something here? What would you suggest? Thanks -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.