我是Jface数据绑定的新手。我正在尝试使用数据绑定来打造表。当任何人点击行时,vales显示在映射的文本字段中。当我这样做时,我得到Exception。(“java.lang.IllegalArgumentException:找不到类类com.swt.pro.model.Employee中具有名称名称的属性“)以下是班级结构。
我有3个Model类,负责填充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中具有名称名称的属性”
请帮我解决异常
答案 0 :(得分:0)
您的课程必须遵循Java Beans规范(请注意,这是不同的“Enterprise Java Beans”,即EJB)。基本上,您需要添加访问器方法(请参阅第7节)并支持PropertyChangeListeners在更新模型时通知UI。