2011-12-11 13 views
1

問題:フォームの読み込み時に、ParentEditor、サブエディタ、ThisEditorが正しく でリストボックス(ドロップダウン)ウィジェット、MyWidgetを含むすべてのフィールドがポップされます。しかし、リストボックスで新しいオプションを選択して保存すると、新しく選択されたオプションは保存されません。他のウィジェットへの編集はうまく節約できます。ドライバがフラッシュされると、エディタはlistBoxの値を取得しないように見えます。デバッグモードでは、driver.edit上で、リストボックスを含むすべてのフォームウィジェットでTakesValueEditorのsetValue(value)呼び出しを見ることができます。しかし、フラッシュすると、TakesValueEditorは他のフォームウィジェットでgetValue()を呼び出すことができますが、 はリストボックスにありません。リストボックスの変更が反映されていないエディタ

エディタ階層:ParentEditor> ThisEditor> MyWidget。 ParentEditorはフォーム全体です。 ThisEditorはフォームのサブセクションです。 MyWidgetはThisEditorセクションのカスタムリストボックスです。

私はMVPパターンを使用しています。以下は、ビューとプレゼンターのサンプルコードスニペットです。

VIEW: 

    /** ThisEditor is a sub-section of ParentEditor (the Form) and contains a 
    MyWidget (custom listbox). */ 
    public class ThisEditor extends Composite implements Editor<ThisProxy>, ThisView { 
    ... //rfeDriver interface defined and created here 

    @UiField 
     MyWidget my; //getMy and setMy methods in ThisProxy 

    ... //other field declarations 

     public ThisEditor() { 
      initWidget(binder.createAndBindUi(this)); 
     } 

    @Override 
     public MyView getMy() { 
      return my; 
     } 
    ... //other methods 
    } 

    /** This is the View interface that MyWidget implements */ 
    public interface MyView extends HasOptions, HasValue<MyProxy>, Focusable { 
     interface Presenter { 
     ... 
    } 
    ... 
    } 

    public class MyWidget extends Composite implements MyView,  
      IsEditor<LeafValueEditor<MyProxy>> { 
    ... 
    @UiField 
     ListBox listBox; //single-select dropdown 
    ... 

    public MyWidget() { 
      initWidget(binder.createAndBindUi(this)); 
     addChangeHandler(); //listen to changes to listBox and setSelectedIndex (?) 
    } 
    ... 
    @Override 
    public int getSelectedIndex() { 
      return listBox.getSelectedIndex(); 
     } 

     @Override 
     public void setSelectedIndex(int index) { 
      listBox.setSelectedIndex(index); 
     } 
    ... 

     /** 
     * Called by the TakesValueEditor on rfeDriver.edit. 
     */ 
    @Override 
     public MyProxy getValue() { 
      //ask presenter for the MyProxy object -- presenter calls 
      //getSelectedIndex() on this widget and returns the object associated 
      //with the index 
      return presenter.getValue(); 
     } 

    /** 
    * Called by the TakesValueEditor on rfeDriver.flush. 
    */ 
    @Override 
    public void setValue(MyProxy value) { 
    //pass the value to the presenter to parse and set the index that corresponds 
    //to this object 
     presenter.setValue(value); 
    } 

PRESENTER 

    public class MyPresenter implements MyView.Presenter,  
      ValueLookupCompleteEventHandler { 
     ... 
    protected HasOptions view; 
    private List<MyProxy> myList; 

    public MyPresenter(ParentPresenter parent) { 
     //setParent for this child presenter 
    } 

    ... //methods to set view and create association between view and presenter 

    @Override 
    public MyProxy getValue() { 
     //identify the current selection 
     String selectedId = view.getValue(view.getSelectedIndex()); 

     if (selectedId != null) { 
      //iterate myList to find the MyProxy object whose id.equals(selectedId) 
      for (Iterator<MyProxy> i = myList.iterator(); i.hasNext();) { 
      MyProxy value = i.next(); 
      if (selectedId.equals(value.getCode().toString())) { 
       return value; 
      } 
     } 
      } 
     return null; 
     } 

    @Override 
    public void setValue(MyProxy value) { 
     //handle null value 
     String selectedId = value.getCode().toString(); 
    ... //verify the value is in myList 

    //traverse dropdown list and set selected index corresponding to value object 
    for (int i = 0; i < view.getItemCount(); ++i) { 
     if (selectedId.equals(view.getValue(i))) { 
      view.setSelectedIndex(i); 
     } 
    } 
    } 
} 

答えて

1

私はこの同じ問題を実行しました。 GWT ListBoxのソースコードを見ると、isEditorを実装していないことになります。私は実際にそれがGWTエディタコンポーネントだとは思わない。理解しづらい。私はそれをコードしなければならなかった。

関連する問題