0

我是 Jface 数据绑定的新手。我正在尝试使用数据绑定填充表。当任何人单击行时,值将显示在映射的文本字段中。当我这样做时,我得到异常。(“java.lang.IllegalArgumentException:在类 com.swt.pro.model.Employee 中找不到名称为 name 的属性") 下面是类结构。

我有 3 个模型类,它们负责填充 1 个 GUI 表

public class WorkplaceDetail extends AbstractModelObject {

private int code;
private String plant;
private String compRegNum;
private final List <Employee> m_employee = new ArrayList();
}

public class Employee extends AbstractModelObject{


private String empName;
private int empNumber;
private List<Address> address = new ArrayList();
}

public class Address extends AbstractModelObject{

private String primaryPhone;
private String secPhone;
}

In main class I am populating value of these models

List<WorkplaceDetail> m_workplace = new ArrayList();

public void initializeModels() {
m_workplace.add(new WorkplaceDetail(1,"IBM","12-02-033",));
WorkplaceDetail workplace= new WorkplaceDetail();
workplace.addEmployee(new Employee ("Prashant",0));
Employee employee= new Employee();
employee.addAddress(new Address("010-674634",null,"010-748347",null,null,null,null,null,null)); 
}

Databinding method

ObservableListContentProvider simpleTableViewerContentProviderList = new ObservableListContentProvider();
IObservableMap[] simpleTableViewerLabelProviderMaps = PojoObservables.observeMaps(simpleTableViewerContentProviderList.getKnownElements(), WorkplaceDetail.class, new String[]{"code","plant", "compRegNum"});
m_workplaceViewer.setLabelProvider(new ObservableMapLabelProvider(simpleTableViewerLabelProviderMaps)); 
m_workplaceViewer.setContentProvider(simpleTableViewerContentProviderList);

WritableList smListWritableList = new WritableList(m_workplace, WorkplaceDetail.class);
m_workplaceViewer.setInput(smListWritableList);

IObservableMap[] _simpleTableViewerLabelProviderMaps = PojoObservables.observeMaps(simpleTableViewerContentProviderList.getKnownElements(), Employee.class, new String[]{"name"});
m_workplaceViewer.setLabelProvider(new ObservableMapLabelProvider(_simpleTableViewerLabelProviderMaps));


IObservableMap[] simpleTableViewerLabelProviderMaps_2 = PojoObservables.observeMaps(simpleTableViewerContentProviderList.getKnownElements(), Address.class, new String[]{ "phone1", "phone2"});
m_workplaceViewer.setLabelProvider(new ObservableMapLabelProvider(simpleTableViewerLabelProviderMaps_2));

当我运行它时,我得到异常“java.lang.IllegalArgumentException:在类 com.swt.pro.model.Employee 中找不到名称为名称的属性”

请帮我解决异常

4

1 回答 1

0

您的类必须遵循Java Beans规范(注意这是不同的“Enterprise Java Beans”又名 EJB)。基本上,您需要添加访问器方法(参见第 7 节)并支持 PropertyChangeListeners 在模型更新时通知 UI。

于 2012-10-31T16:41:42.203 回答