2011-08-01 83 views
3

我想在我的項目中使用GWT的編輯器框架。編輯器字段沒有更新

在我看來,(實現編輯器),我有我的UiBinder的領域:

@UiField 
TextBox text; 

在我的演講我通過GIN注入驅動程序實例:

@Inject 
public AppointmentPopupPresenter(EventBus eventBus, MyView view, final AppointmentDriver appointmentDriver) 

當主持人叫我試試初始化驅動程序:

this.appointmentDriver.initialize(getView()); 
this.appointmentDriver.edit(new Appointment()); 

GINModule:

bind(SimpleBeanEditorDriver.class).to(AppointmentDriver.class); 

AppointmentDriver接口:

public interface AppointmentDriver extends SimpleBeanEditorDriver<Appointment, AppointmentPopupPresenter.MyView>{ 

}

後來當我聽到一個按鈕事件我打電話:

appointmentDriver.flush(); 

,但所有的屬性都爲空,沒有錯誤味精拋出。如果我將調試器放入文本框小部件中,那麼「編輯器」的實例也是空的。不知道內部,但也許這是對你的暗示。

預約POJO(當然與無效的setText(字符串文本)/字符串的getText()):

String text; 

此刻,我完全被卡住所以任何幫助超過歡迎。

謝謝!

回答

1

我看到你做了getView(),它是否返回與傳遞給構造函數的視圖相同的視圖,如ui中所示?可能是驅動程序使用與實際顯示的視圖不同的視圖進行初始化,因此您將從錯誤的視圖中獲取數據。我也不明白你爲什麼要這樣做,看起來沒有必要?

+0

是的,我看着調試器及其正確的視圖。如果我現在 我的司機改變爲顯式的視圖,而不是視圖 接口: 公共接口AppointmentDriver延伸 SimpleBeanEditorDriver <預約,AppointmentPopupView> {} 和driver.initialize((AppointmentPopupView)getView()); 其工作。我真的不知道爲什麼,我覺得有點 與我的主持人演員不舒服。爲什麼綁定是不必要的,我想我以後需要注入它? – Gambo

+0

我想我知道它是什麼。您的驅動程序應該使用'AppointmentPopupView'參數而不是'MyView'進行擴展。因爲基於這些參數,GWT生成驅動程序代碼,你的'AppointmentPopupView'應該實現'Editor',因爲由於GWT的工作方式,它需要每個包含編輯器代碼的類的接口,否則它不能在AppointmentPopupView中看到TextBox。 –

+0

關於綁定。我不熟悉GIN,但是在使用它時,它看起來這意味着當'SimpleBeanEditorDriver'被用作參數時,'AppointmentDriver'被注入。但是在你的代碼中,你直接使用'AppointmentDriver'而不是'SimpleBeanEditorDriver',所以GIN注入並不是'AppointmentDriver',所以不需要綁定。 –

0

我不確定,但我認爲問題在於,您只需撥打SimpleBeanEditorDriver.initialize(E editor)即可。據我記得,你需要撥打RequestFactoryEditorDriver.initialize(EventBus, RequestFactory, E)

也許我的小(現在更新爲GWT 2.3,但仍然完全未拋光)example project可以幫助你。

這裏的片段,我做初始化電話:

final MyRequestFactory requestFactory = GWT 
      .create(MyRequestFactory.class); 
    requestFactory.initialize(eventBus); 

    final MyEditor myEditor = new MyEditor(); 
    driver.initialize(eventBus, requestFactory, myEditor); 

應該可以重構項目使用GIN。

+0

感謝您的幫助,遺憾的是我沒有使用RequestFactory,因爲我正在建立我的json/rest服務,所以我只需要編輯器的東西。無論如何,我會看看你的項目! – Gambo