java - 无法导入 com.vaadin.data.Binder
问题描述
我要导入:import com.vaadin.data.Binder;
但是无法导入。它显示错误The import com.vaadin.data.Binder cannot be resolved
。我正在使用 Vaadin 7。这是一个 Vaadin 示例项目名称 Customer。
Java文件代码如下:
package com.example.tutorial;
import com.vaadin.data.Binder;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.ui.Button;
import com.vaadin.ui.DateField;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.TextField;
import com.vaadin.ui.themes.ValoTheme;
public class CustomerForm extends FormLayout {
private TextField firstName = new TextField("First name");
private TextField lastName = new TextField("Last name");
private TextField email = new TextField("Email");
private NativeSelect<CustomerStatus> status = new NativeSelect<>("Status");
private DateField birthdate = new DateField("Birthday");
private Button save = new Button("Save");
private Button delete = new Button("Delete");
private CustomerService service = CustomerService.getInstance();
private Customer customer;
private MyUI myUI;
private Binder<Customer> binder = new Binder<>(Customer.class);
public CustomerForm(MyUI myUI) {
this.myUI = myUI;
setSizeUndefined();
HorizontalLayout buttons = new HorizontalLayout(save, delete);
addComponents(firstName, lastName, email, status, birthdate, buttons);
status.setItems(CustomerStatus.values());
save.setStyleName(ValoTheme.BUTTON_PRIMARY);
save.setClickShortcut(KeyCode.ENTER);
binder.bindInstanceFields(this);
save.addClickListener(e -> this.save());
delete.addClickListener(e -> this.delete());
}
public void setCustomer(Customer customer) {
this.customer = customer;
binder.setBean(customer);
// Show delete button for only customers already in the database
delete.setVisible(customer.isPersisted());
setVisible(true);
firstName.selectAll();
}
private void delete() {
service.delete(customer);
myUI.updateList();
setVisible(false);
}
private void save() {
service.save(customer);
myUI.updateList();
setVisible(false);
}
}
解决方案
在 Vaadin 8 中引入了 binder 类。对于 Vaadin 7,您可以使用 Fieldgroup。您可以在此处查看官方文档:https ://vaadin.com/docs/v7/framework/datamodel/datamodel-itembinding
Vaadin 7 自 2019 年起停止使用,建议使用 Vaadin 8 或 Vaadin 14。
推荐阅读
- aspectj - 如何修改未知数量的方法参数与方面的方面
- javascript - 为什么我总是得到 Null?
- python - 在pyglet中将具有背景的图像保存为透明
- yaml - 如何在yaml中创建数组?
- javascript - 矢量图层属性不会在函数调用中加载
- java - swagger (springfox) 生成的日期
- javascript - 空闲时 scrollIntoView 不准确
- javascript - 导入声明可能只出现在模块的顶层,尝试 type="module" 只会给我一个新错误
- gradle - 如何为 io.freefair.lombok 设置插件
- r - 如何将行合并为 R 中矩阵旁边的列?