1

我正在开发一个 ExtGWT 3.0 (beta) 应用程序。

我有一个包含一个属性的简单 Java bean:

public class MyBean {
    private String content;

    // getter and setter here...
}

我想将该属性绑定到一个TextField.

我创建了一个界面:

interface MyBeanProperties extends PropertyAccess<MyBean> {
    ValueProvider<MyBean, String> content();
}

但接下来是什么?如何告诉TextField绑定到特定对象的特定MyBean属性?

4

1 回答 1

2

PropertyAccess用于泛指对象属性,通常用于使用Store类似网格或图表的数据小部件。要将表单绑定到 bean,请查看位于http://code.google.com/webtoolkit/doc/latest/DevGuideUiEditors.html的 GWT 编辑器框架。在http://www.sencha.com/examples/#ExamplePlace:basicbinding%28uibinder%29有一些使用 GXT 的示例

粗略地说,您将构建一个包含您需要的所有属性的表单小部件,并为该编辑器及其 bean 创建一个编辑器驱动程序:

public class MyBeanEditor implements Editor<MyBean> {

  // do any kind of widget setup you like, just make sure to have methods/fields
  // package protected or higher that extends Editor (Field extends Editor)

  TextField content;
}

//... declare the driver
interface Driver extends SimpleBeanEditorDriver<MyBean, MyBeanEditor> {}

//... use the driver to bind a form to a bean
Driver driver = GWT.create(Driver.class);
driver.initialize(myBeanEditorInstance);
driver.edit(myBean);

//... when save is clicked (or a timer, or whatever), get the value and do 
//    something with it
MyBean model = driver.flush();
于 2012-02-22T17:27:42.243 回答