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

发布于 2025-01-08 20:56:13 字数 465 浏览 1 评论 0原文

我正在开发 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 对象的特定属性?

I am working on a ExtGWT 3.0 (beta) application.

I have a simple Java bean containing one property:

public class MyBean {
    private String content;

    // getter and setter here...
}

I want to bind the property to a TextField.

I have created an interface:

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

But what's next? How do I tell the TextField to bind to that particular property of a particular MyBean object?

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

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

发布评论

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

评论(1

红尘作伴 2025-01-15 20:56:13

PropertyAccess 用于一般引用对象属性,通常用于使用 Store(如网格或图表)的数据小部件。要将表单绑定到 Bean,请查看 GWT 的编辑器框架,网址为 http://code .google.com/webtoolkit/doc/latest/DevGuideUiEditors.html。在 http://www.sencha.com 上有一些 GXT 的示例/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();

PropertyAccess is used to generically refer to an objects properties, often for data widgets that use a Store like the grid or charts. For binding a form to a bean, check out GWT's editor framework at http://code.google.com/webtoolkit/doc/latest/DevGuideUiEditors.html. There are some examples for this with GXT at http://www.sencha.com/examples/#ExamplePlace:basicbinding%28uibinder%29

Roughly, you'll build a form widget that wraps all the properties you need, and make an editor driver for that editor and its 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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文