作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我使用 springboot 的 vaadin 流程项目中,我遇到了无法绑定(bind)带有组合框的枚举值的问题。我在下面提供了我的代码。这里有谁能帮帮我吗?
组合框实例化:
private ComboBox<Country> nationality = new CompoBox<>("Nationality");
绑定(bind)代码:
binder.forField(nationality)
.bind(Coach::getNationality,Coach:setNationality);
最佳答案
我认为您缺少 setItems
调用。这是一个基于 Project Base for Vaadin Flow 的示例
package com.vaadin.starter.skeleton;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
/**
* The main view contains a button and a click listener.
*/
@Route("")
@PWA(name = "Project Base for Vaadin Flow", shortName = "Project Base")
public class MainView extends VerticalLayout {
public MainView() {
ComboBox<ENUM> comboBox = new ComboBox<ENUM>("Number");
comboBox.setItems(ENUM.values());
Binder<Bean> binder = new Binder<>();
binder.setBean(new Bean());
binder.bind(comboBox,Bean::getField,Bean::setField);
Button button = new Button("Check value",
e-> Notification.show("Value in bean is " + binder.getBean().getField()));
add(button,comboBox);
}
public enum ENUM {
ONE,TWO,TREE
}
public static class Bean {
private ENUM field;
public ENUM getField() {
return field;
}
public void setField(ENUM field) {
this.field = field;
}
}
}
关于vaadin - 如何在 vaadin 流中绑定(bind)枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55193482/
我是一名优秀的程序员,十分优秀!