Tuesday, May 29, 2012

Re: Editor persist throws "A request is already in progress "

A RequestContext is a "builder"; you queue things into it and then fire(). Once fire()d, it's no longer usable; you have to create a new one and start over.

On Tuesday, May 29, 2012 2:02:07 AM UTC+2, jmbz84 wrote:
Hello,

I'm trying to set up a basic editor in gwt. Everything works fine, the
editor displays the data and saves but when I try to save again (i.e.
press the save button 2 times) it throws me the error "A request is
already in progress " in the second save, but the first time the
editor saves the data correctly.

How can I solve this, perhaps creating a new Request?

//
//Methods that edit and save the editor, locate in
ComposerEditorContainer class
//
public void edit(RequestContext requestContext) {

                editorDriver = GWT.create(Driver.class);
                editorDriver.initialize(requestFactory, composerEditor);
                editorDriver.edit(composer, requestContext);
        }

public void save() {

                ComposerRequest composerRequest = (ComposerRequest) editorDriver
                                .flush();
                ComposerProxy newProxy = composerRequest.edit(composer);
                composerRequest.persist(newProxy).fire();
        }

//
//Events in a presenter that save and initialize the editor
//
                eventBus.addHandler(SaveButtonClickedEvent.TYPE,
                                new SaveButtonClickedEventHandler() {
                                        @Override
                                        public void onSaveButtonClicked(SaveButtonClickedEvent event) {

                                                ((ComposerEditorContainer) composerEditorContainer)
                                                                .save();
                                        }

                                });

//this method gets the ComposerProxy from the event and initializes
the editor
//
                eventBus.addHandler(BrowserItemClickedEvent.TYPE,
                                new BrowserItemClickedEventHandler() {
                                        @Override
                                        public void onBrowserItemClicked(
                                                        BrowserItemClickedEvent event) {


                                                requestFactory = GWT.create(AppRequestFactory.class);
                                                requestFactory.initialize(new SimpleEventBus());

                                                ComposerRequest request = requestFactory
                                                                .getComposerRequest();

                                                Request<ComposerProxy> req = request.findComposer(event
                                                                .getclickedItem().getValue());

                                                req.fire(new Receiver<ComposerProxy>() {

                                                        public void onSuccess(ComposerProxy arg0) {

                                                                ComposerEditorContainer editorContainer = new
ComposerEditorContainer(
                                                                                requestFactory, arg0);
                                                                editorContainer.edit(requestFactory
                                                                                .getComposerRequest());
                                                                view.clear();
                                                                view.addWidget(editorContainer);

                                                                composerEditorContainer = editorContainer;
                                                        }
                                                });

                                        }
                                });


//Error that appears when saving for the second time
Caused by: java.lang.IllegalStateException: A request is already in
progress
    at
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.checkLocked(AbstractRequestContext.java:
960)
    at
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.editProxy(AbstractRequestContext.java:
510)
    at
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.edit(AbstractRequestContext.java:
502)
    at
com.google.test.client.editor.ComposerEditorContainer.save(ComposerEditorContainer.java:
58)
    at com.google.test.client.presenter.BrowserDetailPresenter
$1.onSaveButtonClicked(BrowserDetailPresenter.java:48)
    at
com.google.test.client.event.SaveButtonClickedEvent.dispatch(SaveButtonClickedEvent.java:
17)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/ZTLkfXUQ2vUJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment