编辑器未获取列表框更改

发布于 2024-12-20 18:02:55 字数 3892 浏览 1 评论 0原文

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

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

我正在使用 MVP 模式。以下是 View 和 Presenter 的示例代码片段:

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);
       }
   }
    }
}

Issue: On load of a form, ParentEditor, a sub-editor, ThisEditor, properly
popluates all its fields including a listbox(dropdown) widget, MyWidget. However,if I select a new option in the listbox and save, it doesn't save the newly selected option; though edits to other widgets are saving fine. It appears that on a driver flush, the editor does not get the value in my listBox. In debug mode, on driver.edit, I can see the TakesValueEditor call setValue(value) on all form widgets including the listbox. But on flush, I can see the TakesValueEditor call its getValue() on other form widgets but
not on my listbox.

The editor hierarchy: ParentEditor > ThisEditor > MyWidget. ParentEditor is the entire form. ThisEditor is a sub-section of the form. MyWidget is a custom listbox in ThisEditor section.

I'm using MVP pattern. Below are sample code snippets of the View and Presenter:

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);
       }
   }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2024-12-27 18:02:55

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

I just ran into this same issue. If you look at the source code for the GWT ListBox, you'll se e that it does not implement isEditor. I actually don't think it is a GWT editor component. Hard to understand. I had to code around it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文