Gwt 编辑器未获取列表框更改

Gwt 编辑器未获取列表框更改,gwt,gwt-editors,Gwt,Gwt Editors,问题:加载表单时,正确选择ParentEditor、子编辑器、ThisEditor 弹出它的所有字段,包括一个列表框(下拉)小部件MyWidget。但是,如果我在列表框中选择一个新选项并保存,它不会保存新选择的选项;尽管对其他小部件的编辑保存得很好。在驱动程序刷新时,编辑器似乎没有获取我的列表框中的值。在调试模式下,在driver.edit上,我可以看到TakesValueEditor在包括listbox在内的所有表单小部件上调用setValue(value)。但是在flush上,我可以看到Ta

问题:加载表单时,正确选择ParentEditor、子编辑器、ThisEditor 弹出它的所有字段,包括一个列表框(下拉)小部件MyWidget。但是,如果我在列表框中选择一个新选项并保存,它不会保存新选择的选项;尽管对其他小部件的编辑保存得很好。在驱动程序刷新时,编辑器似乎没有获取我的列表框中的值。在调试模式下,在driver.edit上,我可以看到TakesValueEditor在包括listbox在内的所有表单小部件上调用setValue(value)。但是在flush上,我可以看到TakesValueEditor在其他表单小部件上调用其getValue() 我的列表框上没有

编辑器层次结构:ParentEditor>ThisEditor>MyWidget。ParentEditor是整个表单。此编辑器是表单的一个子部分。MyWidget是此编辑器部分中的自定义列表框

我使用的是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);
       }
   }
    }
}
视图:
/**此编辑器是ParentEditor(表单)的一个子部分,包含
MyWidget(自定义列表框)*/
公共类ThisEditor扩展了复合实现编辑器ThisView{
…//rfeDriver接口在此处定义和创建
@尤菲尔德
MyWidget my;//此代理中的getMy和setMy方法
…//其他字段声明
公共编辑(){
initWidget(binder.createAndBindUi(this));
}
@凌驾
公共MyView getMy(){
归还我的;
}
…//其他方法
}
/**这是MyWidget实现的视图界面*/
公共接口MyView扩展了HasOptions、HasValue和Focusable{
界面演示者{
...
}
...
}
公共类MyWidget扩展复合实现MyView,
编辑{
...
@尤菲尔德
ListBox ListBox;//单选下拉列表
...
公共MyWidget(){
initWidget(binder.createAndBindUi(this));
addChangeHandler();//侦听对listBox和setSelectedIndex(?)的更改
}
...
@凌驾
public int getSelectedIndex(){
返回listBox.getSelectedIndex();
}
@凌驾
公共无效集合选定索引(整数索引){
listBox.setSelectedIndex(索引);
}
...
/**
*由rfeDriver.edit上的TakesValue编辑器调用。
*/
@凌驾
公共MyProxy getValue(){
//向演示者询问MyProxy对象--演示者调用
//getSelectedIndex()并返回关联的对象
//使用索引
返回presenter.getValue();
}
/**
*由rfeDriver.flush上的TakesValue编辑器调用。
*/
@凌驾
公共无效设置值(MyProxy值){
//将值传递给演示者以解析和设置对应的索引
//为了这个目标
presenter.setValue(值);
}
节目主持人
公共类MyPresenter实现MyView.Presenter,
ValueLookupCompleteTeventhandler{
...
保护选项视图;
私人名单;
公共MyPresenter(父级Presenter父级){
//设置此子演示者的父级
}
…//设置视图并在视图和演示者之间创建关联的方法
@凌驾
公共MyProxy getValue(){
//确定当前选择
字符串selectedId=view.getValue(view.getSelectedIndex());
如果(selectedId!=null){
//迭代myList以查找id.equals的MyProxy对象(SelecteId)
for(迭代器i=myList.Iterator();i.hasNext();){
MyProxy值=i.next();
if(selectedId.equals(value.getCode().toString())){
返回值;
}
} 
}
返回null;
}
@凌驾
公共无效设置值(MyProxy值){
//句柄空值
字符串selectedId=value.getCode().toString();
…//验证该值是否在myList中
//遍历下拉列表并设置值对象对应的选定索引
对于(int i=0;i
我刚刚遇到了同一个问题。如果你看一下GWT列表框的源代码,你会发现它没有实现isEditor。我实际上不认为它是GWT编辑器组件。很难理解。我必须对它进行编码。

我刚刚遇到了同一个问题。如果你看一下GWT列表框的源代码,你会发现这一点它没有实现isEditor。我实际上不认为它是GWT编辑器组件。很难理解。我必须围绕它编写代码