将bean属性绑定到GXT 3.0中的TextField

时间:2012-02-22 13:28:32

标签: gwt binding gxt gwt-editors

我正在开发ExtGWT 3.0(测试版)应用程序。

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

public class MyBean {
    private String content;

    // getter and setter here...
}

我想将属性绑定到TextField

我创建了一个界面:

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

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

1 个答案:

答案 0 :(得分:2)

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

有一些例子

粗略地说,您将构建一个表单窗口小部件,它包装您需要的所有属性,并为该编辑器及其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();
相关问题