3.5.2.4.1. UiComponents

UiComponents 是个工厂类,可以使用该类按名称、类或者类型标识创建 UI 组件。

如果创建关联数据的组件,使用类型标识执行特定值类型来对组件进行参数化。比如对于 LabelTextField 或者 DateField 组件,使用类型标识 TextField.TYPE_INTEGER。当创建关联到实体的组件,比如 PickerFieldLookupField 或者 Table,使用静态的 of() 方法来获取合适的类型标识。对于其它组件和容器,使用组件类作为参数。

示例:

  1. @Inject
  2. private UiComponents uiComponents;
  3. @Subscribe
  4. protected void onInit(InitEvent event) {
  5. // components working with simple data types
  6. Label<String> label = uiComponents.create(Label.TYPE_STRING);
  7. TextField<Integer> amountField = uiComponents.create(TextField.TYPE_INTEGER);
  8. LookupField<String> stringLookupField = uiComponents.create(LookupField.TYPE_STRING);
  9. // components working with entities
  10. LookupField<Customer> customerLookupField = uiComponents.create(LookupField.of(Customer.class));
  11. PickerField<Customer> pickerField = uiComponents.create(PickerField.of(Customer.class));
  12. Table<OrderLine> table = uiComponents.create(Table.of(OrderLine.class));
  13. // other components and containers
  14. Button okButton = uiComponents.create(Button.class);
  15. VBoxLayout vBox = uiComponents.create(VBoxLayout.class);
  16. // ...
  17. }