Asynchronuos callback saves value but prints FAILED

Posted by sprasad12 on Stack Overflow See other posts from Stack Overflow or by sprasad12
Published on 2010-03-18T23:44:19Z Indexed on 2010/03/18 23:51 UTC
Read the original article Hit count: 580

Hi,

I am using nested Asynchronous callbacks to save my front-end data to the back-end database. The data is being save into the tables the way i want them to, but it is printing that it failed. Here is the code:

    oksave.addClickHandler(new ClickHandler(){
                        public void onClick(ClickEvent event) {
                            if(erasync == null)
                                erasync = GWT.create(EntityRelationService.class);
                            AsyncCallback<Void> callback = new AsyncCallback<Void>(){
                                public void onFailure(Throwable caught) {
                                    String msg = caught.getLocalizedMessage();
                                     if (caught instanceof NotFoundException) {
                                        msg = ((NotFoundException) caught).getType()
                                              + ((NotFoundException) caught).getMessage();
                                     }
                                   System.out.println("Failed" + msg);
}
                                public void onSuccess(Void result) {
                                    Label success = new Label("Name : " + pname.getText() + " was successfully saved");
                                    Button close = new Button("close");
                                    VerticalPanel sp = new VerticalPanel();
                                    d1 = new DialogBox();
                                    sp.add(success);
                                    sp.add(close);

                                    close.addClickHandler(new ClickHandler(){
                                        @Override
                                        public void onClick(ClickEvent event) { 
                                            if(erasync == null)
                                                erasync = GWT.create(EntityRelationService.class);
                                            AsyncCallback<Void> callbackOthers = new AsyncCallback<Void>(){
                                                @Override
                                                public void onFailure(Throwable caught) {
                                                    String msg = caught.getLocalizedMessage();
                                                     if (caught instanceof NotFoundException) {
                                                        msg = ((NotFoundException) caught).getType()
                                                              + ((NotFoundException) caught).getMessage();
                                                     }
                                                   System.out.println("Failed" + msg);
                                                }

                                                @Override
                                                public void onSuccess(Void result) {
                                                    System.out.println("Success");
                                                }                           
                                            };
erasync.setEntityType(name, top, left, pname, callbackOthers);
});
};
erasync.setProject(name, callback);
});

Here it prints successful for the first callback, but for the nested one it says failed though it saves the value.

Am i missing something?

Any input will be of great help. Thank you.

© Stack Overflow or respective owner

Related posts about asynchronous

Related posts about asynccallback