我正在学习Eclipse Scout ...我已连接到Sql server,使用Object [] []获取数据...现在,我想使用bean,beanarray holder获取数据... 我不知道这个过程......
我创建了bean用户!
我使用服务填充bean,使用此示例:http://www.eclipse.org/forums/index.php/t/310526/
因此,有人可以解释如何在侦察中使用bean,填充表格或表单......
TNX
答案 0 :(得分:0)
如果你正在使用这样的普通旧java对象(POJO):
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;
}
}
您可以像这样填充这些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();
}
要填充表格,您需要手动完成。例如,在客户端:
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);
}
映射服务器端也是可能的。但在这种情况下,您应该明确考虑使用表数据(参见下一节)
您应该确保使用基于bean的TableData。阅读此答案,了解如何区分table based TableData and bean based TableData。
假设您的表单中有这样的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");
}
}
}
}
您应该可以在服务中执行类似的操作:
UserTableRowData rowData = formData.getUserTable().addRow();
rowData.setFirstName("John");
rowData.setLastName("Smith");
如果您想要填充表格的SQL查询,而不是手动添加行,您可以执行以下操作:
BeanArrayHolder<User> beansArray = new BeanArrayHolder<User>(User.class);
SQL.selectInto(" select first_name, last_name " +
" from users " +
" into :{UserTable.FirstName}, :{UserTable.LastName} ", formData);
对于TablePageData,它的工作方式相同,请参阅我们的教程中的示例:
MiniCrm Tutorial > Write the first page > Load data on the server