简体   繁体   English

Bean数组Eclipse Scout示例

[英]bean array eclipse scout sample

I am learning Eclipse Scout... I have connected to Sql server, fetching data using Object[][]...now, I want to fetch data using beans, beanarray holder... I dont know the process... 我正在学习Eclipse Scout ...我已经连接到Sql服务器,使用Object [] []来获取数据...现在,我想使用bean,beanarray持有者来获取数据...我不知道该过程...

I have created bean Users! 我已经创建了bean用户!
I have populated bean using service, using this example: http://www.eclipse.org/forums/index.php/t/310526/ 我使用以下示例使用服务填充了bean: http : //www.eclipse.org/forums/index.php/t/310526/

So can someone explain how to use beans in scout, to populate table, or form... 有人可以解释一下如何在侦察中使用bean,填充表或表格...

  1. Make a bean example: users 举例说明:用户
  2. Fill the bean in service example: get user data from users table 填写服务示例中的bean:从用户表获取用户数据
  3. populate table using that bean... 使用该bean填充表...

tnx TNX

Java POJO (bean) Java POJO(bean)

If you are working with plain old java object (POJO) like this: 如果您正在使用普通的老式Java对象(PO​​JO),如下所示:

public class User {
    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

You can populate an array of those POJO like this: 您可以像这样填充这些POJO的数组:

public User[] loadAll() throws ProcessingException {
  BeanArrayHolder<User> beansArray = new BeanArrayHolder<User>(User.class);

  SQL.selectInto(" select first_name, last_name " +
      " from users " +
      " into :{FirstName}, :{LastName} ", beansArray);

  return beansArray.getBeans();
}

To populate your table, you need to do it by hand. 要填充表格,您需要手工完成。 For example on the client side: 例如在客户端:

for (User user : beansArray.getBeans()) {
  ITableRow row = getTable().createRow();
  getTable().getNameColumn().setValue(row, user.getLastName());
  getTable().getFirstNameColumn().setValue(row, user.getFirstName());
  getTable().addRow(row, true);
}

A mapping server side is also possible. 映射服务器端也是可能的。 But in this case, you should definitively consider to use table data (see the next section) 但是在这种情况下,您应该明确考虑使用表数据(请参阅下一节)


Table data 表数据

You should ensure that you are using bean based TableData. 您应该确保使用的是基于bean的TableData。 Read this answer to know how you can differentiate table based TableData and bean based TableData . 阅读此答案,以了解如何区分基于表的TableData和基于bean的TableData

Assuming you have a UserTableField like this in your Form: 假设您的窗体中有一个像这样的UserTableField:

@Order(10.0)
@FormData(sdkCommand = FormData.SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = FormData.DefaultSubtypeSdkCommand.CREATE)
public class UserTableField extends AbstractTableField<UserTableField.Table> {

  @Order(10.0)
  public class Table extends AbstractExtensibleTable {

    public LastNameColumn getLastNameColumn() {
      return getColumnSet().getColumnByClass(LastNameColumn.class);
    }

    public FirstNameColumn getFirstNameColumn() {
      return getColumnSet().getColumnByClass(FirstNameColumn.class);
    }

    @Order(10.0)
    public class FirstNameColumn extends AbstractStringColumn {

      @Override
      protected String getConfiguredHeaderText() {
        return TEXTS.get("FirstName");
      }
    }

    @Order(20.0)
    public class LastNameColumn extends AbstractStringColumn {

      @Override
      protected String getConfiguredHeaderText() {
        return TEXTS.get("LastName");
      }
    }
  }
}

You should be able to do something like that in your service: 您应该能够在服务中执行类似的操作:

UserTableRowData rowData = formData.getUserTable().addRow();
rowData.setFirstName("John");
rowData.setLastName("Smith");

Instead of adding the rows manualy, if you want to have a SQL query to populate the table, you can do something like that: 如果您要使用SQL查询来填充表,而不是手动添加行,则可以执行以下操作:

BeanArrayHolder<User> beansArray = new BeanArrayHolder<User>(User.class);

SQL.selectInto(" select first_name, last_name " +
      " from users " +
      " into :{UserTable.FirstName}, :{UserTable.LastName} ", formData);

It works the same way for TablePageData, see an example in our tutorial: 它对TablePageData的工作方式相同,请参见本教程中的示例:

MiniCrm Tutorial > Write the first page > Load data on the server MiniCrm教程>编写第一页>在服务器上加载数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM