【问题标题】:Editor Fields are not updating编辑器字段未更新
【发布时间】:2011-08-01 22:11:03
【问题描述】:

我想在我的项目中使用 GWT 的 Editor Framework。

在我的视图(实现编辑器)中,我有我的 UiBinder 字段:

@UiField
TextBox text;

在我的 Presenter 中,我通过 GIN 注入驱动程序实例:

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

当演示者被调用时,我尝试使用以下命令初始化驱动程序:

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

GIN 模块:

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

AppointmentDriver 接口:

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

}

稍后当我听到我调用的按钮事件时:

appointmentDriver.flush();

但是所有属性都是空的并且没有错误消息被抛出。如果我在调试器中查看文本框小部件,“编辑器”的实例也为空。不知道internas,但也许这对你来说是一个提示。

约会POJO(当然用void setText(String text)/String getText()):

 String text;

目前我完全陷入困境,所以任何帮助都非常受欢迎。

谢谢!!

【问题讨论】:

    标签: gwt gwt-editors


    【解决方案1】:

    我看到你做了一个 getView() ,它返回的视图是否与传递给构造函数的视图相同,并且与 ui 中显示的相同?可能是驱动程序使用与实际显示的视图不同的视图进行初始化,因此您将从不正确的视图中获取数据。我也不明白你为什么要绑定,好像没必要?

    【讨论】:

    • 是的,我查看了调试器及其正确视图。如果我现在将我的驱动程序更改为显式视图而不是视图界面: public interface AppointmentDriver extends SimpleBeanEditorDriver{} 和 driver.initialize((AppointmentPopupView)getView());它的工作。我真的不知道为什么,我对我的主持人的演员阵容感到有点不舒服。为什么绑定是不必要的,我想我以后需要它来注入它?
    • 我想我知道它是什么。您的驱动程序应该使用AppointmentPopupView 参数而不是MyView 进行扩展。因为基于这些参数 GWT 生成驱动程序代码也你的 AppointmentPopupView 应该实现 Editor 因为由于 GWT 的工作方式,它需要每个包含编辑器代码的类的接口,否则它无法在 te AppointmentPopupView 中看到 TextBox。
    • 关于绑定。我对 GIN 不熟悉,但是当您使用它时,在我看来这意味着当 SimpleBeanEditorDriver 用作参数时,AppointmentDriver 被注入。但是在您的代码中,您直接使用AppointmentDriver 而不是SimpleBeanEditorDriver,因此GIN 注入不使用AppointmentDriver,因此不需要绑定。
    • 希尔布兰德,感谢您的回答。这正是问题所在。关于杜松子酒,你也是对的,因为将它与杜松子酒绑定完全没有意义......
    【解决方案2】:

    我不确定,但我认为问题在于,您只是在调用SimpleBeanEditorDriver.initialize(E editor)。据我记得,你需要拨打RequestFactoryEditorDriver.initialize(EventBus, RequestFactory, E)

    也许我的小宝贝(现在已针对 GWT 2.3 进行了更新,但仍未完善)example project 可以帮助您。

    这是我进行初始化调用的 sn-p:

        final MyRequestFactory requestFactory = GWT
                .create(MyRequestFactory.class);
        requestFactory.initialize(eventBus);
    
        final MyEditor myEditor = new MyEditor();
        driver.initialize(eventBus, requestFactory, myEditor);
    

    应该可以重构项目以使用 GIN。

    【讨论】:

    • 感谢您的帮助,遗憾的是我没有使用 RequestFactory,因为我正在构建我的 json/rest 服务,所以我只需要编辑器的东西。无论如何,我会看看你的项目!
    猜你喜欢
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多