编辑坚持抛出“请求已在进行中”

时间:2012-05-29 04:43:20

标签: java gwt requestfactory

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

// 
//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.java: 17)

1 个答案:

答案 0 :(得分:3)

谷歌集团回答:https://groups.google.com/d/msg/google-web-toolkit/TfXd_SEJF30/ZTLkfXUQ2vUJ

  

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