2

我正在尝试在 gwt 中设置一个基本编辑器。一切正常,编辑器显示数据并保存,但是当我再次尝试保存(即按保存按钮 2 次)时,它会在第二次保存时向我抛出错误“A request is already in progress”,但第一次编辑器正确保存数据。

// 
//Methods that edit and save the editor, located 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 in ComposerEditorContainer (above)
// 
                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; 
                                                        } 
                                                }); 
                                        } 
                                }); 

//第二次保存时出现的错误

原因:java.lang.IllegalStateException:com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.checkLocked(AbstractRequestContext.java: 960) 的请求已经在 com.google.web.bindery.requestfactory .shared.impl.AbstractRequestContext.editProxy(AbstractRequestContext.java: 510) 在 com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.edit(AbstractRequestContext.java: 502) 在 com.google.test.client.editor .ComposerEditorContainer.save(ComposerEditorContainer.java: 58) 在 com.google.test.client.presenter.BrowserDetailPresenter $1.onSaveButtonClicked(BrowserDetailPresenter.java:48) 在 com.google.test.client.event.SaveButtonClickedEvent.dispatch(SaveButtonClickedEvent.爪哇:17)

4

1 回答 1

3

在谷歌组上回答:https ://groups.google.com/d/msg/google-web-toolkit/TfXd_SEJF30/ZTLkfXUQ2vUJ

RequestContext 是一个“构建器”;你把东西排队,然后fire()。一旦 fire()d,它就不再可用了;你必须创建一个新的并重新开始。

于 2012-05-29T08:07:53.767 回答