Java Vaadin表单引发不存在的语法错误
我正在尝试为一个学生项目创建一个示例CRM。目前,我正在STS4中使用springboot和vaadin。我使用他们的烹饪书和vaading crm教程中的组件,以及github中他们书店的示例项目作为模板(我有点混淆了这两个元素,也许是我缺乏理解导致了这个问题)。在提交表单中,第67行和第49行出现以下错误:“令牌上的语法错误”;“,{应在此标记之后”和“语法错误,插入“}”以完成块”。我正在添加我的完整表格供您检查,希望有人能向我解释错误的原因。以下是“我的”代码:Java Vaadin表单引发不存在的语法错误,java,spring-boot,validation,crm,vaadin14,Java,Spring Boot,Validation,Crm,Vaadin14,我正在尝试为一个学生项目创建一个示例CRM。目前,我正在STS4中使用springboot和vaadin。我使用他们的烹饪书和vaading crm教程中的组件,以及github中他们书店的示例项目作为模板(我有点混淆了这两个元素,也许是我缺乏理解导致了这个问题)。在提交表单中,第67行和第49行出现以下错误:“令牌上的语法错误”;“,{应在此标记之后”和“语法错误,插入“}”以完成块”。我正在添加我的完整表格供您检查,希望有人能向我解释错误的原因。以下是“我的”代码: package com.
package com.vaadin.tutorial.crm.UI.views.list;
导入com.vaadin.flow.component.component;
导入com.vaadin.flow.component.ComponentEvent;
导入com.vaadin.flow.component.ComponentEventListener;
导入com.vaadin.flow.component.HasValue;
导入com.vaadin.flow.component.Key;
导入com.vaadin.flow.component.button.button;
导入com.vaadin.flow.component.button.ButtonVariant;
导入com.vaadin.flow.component.checkbox.CheckboxGroup;
导入com.vaadin.flow.component.checkbox.CheckboxGroupVariant;
导入com.vaadin.flow.component.combobox.combobox;
导入com.vaadin.flow.component.formlayout.formlayout;
导入com.vaadin.flow.component.select.select;
导入com.vaadin.flow.component.listbox.listbox;
导入com.vaadin.flow.component.notification.notification;
导入com.vaadin.flow.component.KeyModifier;
导入com.vaadin.flow.component.html.Div;
导入com.vaadin.flow.component.html.Span;
导入com.vaadin.flow.component.orderedlayout.HorizontalLayout;
导入com.vaadin.flow.component.orderedlayout.VerticalLayout;
导入com.vaadin.flow.component.textfield.EmailField;
导入com.vaadin.flow.component.textfield.NumberField;
导入com.vaadin.flow.component.textfield.textfield;
导入com.vaadin.flow.data.binder.BeanValidationBinder;
导入com.vaadin.flow.data.binder.binder;
导入com.vaadin.flow.data.binder.Result;
导入com.vaadin.flow.data.binder.ValidationException;
导入com.vaadin.flow.data.binder.ValueContext;
导入com.vaadin.flow.shared.Registration;
导入com.vaadin.tutorial.crm.backend.entity.Disponibilite;
导入com.vaadin.tutorial.crm.backend.entity.Livre;
导入com.vaadin.tutorial.crm.backend.entity.Livre.Categorie;
导入com.vaadin.tutorial.crm.backend.entity.Stock;
导入com.vaadin.flow.data.converter.converter;
导入com.vaadin.flow.data.converter.StringToIntegerConverter;
导入java.util.List;
导入java.util.Set;
公共课改革扩大了课堂布局{
私人生活;
私有最终选择Disposibilite;
私人最终文本字段库存计数;
TextField titreLivre=新TextField(“titreLivre”);
TextField description=新的TextField(“description”);
TextField auteur=新TextField(“auteur”);
TextField refeni=新的TextField(“refeni”);
TextField isbn=新的TextField(“isbn”);
stockCount=新文本字段(“库存”);
stockCount.addThemeVariants(textfield variant.LUMO\u ALIGN\u RIGHT);
stockCount.setValueChangeMode(ValueChangeMode.EAGER);
disponibilite=新选择();
设置标签(“disponibilite”);
disponibilite.setWidth(“100%”);
setItems(disponibilite.values());
content.add(disponibilite);
组合框分类=新组合框(“分类”);
ListBox stock=new ListBox();
ComboBox校园=新的ComboBox(“校园”);
按钮保存=新按钮(“保存”);
按钮删除=新按钮(“删除”);
按钮关闭=新按钮(“取消”);
活页夹=新的BeanValidationBinder(活页夹等级);
公共部门改革(股票上市){
addClassName(“livre表格”);
binder.bindInstanceFields(本);
库存。设置项目(库存);
setItems(disponibilite.values());
categorie.setItems(Livre.categorie.values());
setItems(Livre.campus.values());;
添加(标题:,
描述
导演,
雷菲尼,
isbn,
有争议的,
分类,
校园
股票
createButtonsLayout());
}
公共空间塞利夫雷(利夫雷-利夫雷){
this.livre=livre;
binder.readBean(livre);
}
私有组件createButtonsLayout(){
save.addThemeVariants(按钮variant.LUMO_PRIMARY);
delete.addThemeVariants(按钮变量.LUMO_错误);
关闭。添加变量(按钮变量。LUMO_第三级);
保存。添加单击快捷方式(键。输入);
close.addClickShortcut(Key.ESCAPE);
save.addClickListener(事件->validateAndSave());
delete.addClickListener(事件->fireEvent(新的DeleteEvent(this,livre)));
close.addClickListener(事件->fireEvent(新建CloseEvent(此)));
binder.addStatusChangeListener(e->save.setEnabled(binder.isValid());
返回新水平布局(保存、删除、关闭);
}
私有void validateAndSave(){
试一试{
binder.Writeban(利弗尔);
fireEvent(新的SaveEvent(this,livre));
}捕获(ValidationException e){
e、 printStackTrace();
}
}
公共静态抽象类LivreFormEvent扩展了ComponentEvent{
/**
*
*/
私有静态最终长serialVersionUID=-7236023661050023675L;
私人生活;
受保护的LivreFormEvent(LivreForm源,Livre-Livre){
超级(来源,假);
this.livre=livre;
}
公共Livre getLivre(){
回归生活;
}
}
公共静态类SaveEvent扩展了公共静态类SaveEvent{
SaveEvent(livrorm源代码,Livre-Livre){
超级(来源:livre);
}
}
公共统计
package com.vaadin.tutorial.crm.UI.views.list;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.checkbox.CheckboxGroup;
import com.vaadin.flow.component.checkbox.CheckboxGroupVariant;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.listbox.ListBox;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.KeyModifier;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.Result;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.data.binder.ValueContext;
import com.vaadin.flow.shared.Registration;
import com.vaadin.tutorial.crm.backend.entity.Disponibilite;
import com.vaadin.tutorial.crm.backend.entity.Livre;
import com.vaadin.tutorial.crm.backend.entity.Livre.Categorie;
import com.vaadin.tutorial.crm.backend.entity.Stock;
import com.vaadin.flow.data.converter.Converter;
import com.vaadin.flow.data.converter.StringToIntegerConverter;
import java.util.List;
import java.util.Set;
public class LivreForm extends FormLayout{
private Livre livre;
private final Select<Disponibilite> disponibilite;
private final TextField stockCount;
TextField titreLivre = new TextField("titreLivre");
TextField description = new TextField("description");
TextField auteur = new TextField("auteur");
TextField refeni = new TextField("refeni");
TextField isbn = new TextField("isbn");
stockCount = new TextField("In stock");
stockCount.addThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
stockCount.setValueChangeMode(ValueChangeMode.EAGER);
disponibilite = new Select<>();
disponibilite.setLabel("Disponibilite");
disponibilite.setWidth("100%");
disponibilite.setItems(Disponibilite.values());
content.add(disponibilite);
ComboBox<Livre.Categorie> categorie = new ComboBox<>("Categorie");
ListBox<Stock> stock = new ListBox<Stock>();
ComboBox<Livre.Campus> campus = new ComboBox<>("Campus");
Button save = new Button("Save");
Button delete = new Button("Delete");
Button close = new Button("Cancel");
Binder<Livre> binder = new BeanValidationBinder<>(Livre.class);
public LivreForm(List<Stock> stocks) {
addClassName("livre-form");
binder.bindInstanceFields(this);
stock.setItems(stocks);
disponibilite.setItems(Disponibilite.values());
categorie.setItems(Livre.Categorie.values());
campus.setItems(Livre.Campus.values());;
add(titreLivre,
description,
auteur,
refeni,
isbn,
disponibilite,
categorie,
campus,
stock,
createButtonsLayout());
}
public void setLivre(Livre livre) {
this.livre = livre;
binder.readBean(livre);
}
private Component createButtonsLayout() {
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
delete.addThemeVariants(ButtonVariant.LUMO_ERROR);
close.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
save.addClickShortcut(Key.ENTER);
close.addClickShortcut(Key.ESCAPE);
save.addClickListener(event -> validateAndSave());
delete.addClickListener(event -> fireEvent(new DeleteEvent(this, livre)));
close.addClickListener(event -> fireEvent(new CloseEvent(this)));
binder.addStatusChangeListener(e -> save.setEnabled(binder.isValid()));
return new HorizontalLayout(save, delete, close);
}
private void validateAndSave() {
try {
binder.writeBean(livre);
fireEvent(new SaveEvent(this, livre));
} catch (ValidationException e) {
e.printStackTrace();
}
}
public static abstract class LivreFormEvent extends ComponentEvent<LivreForm> {
/**
*
*/
private static final long serialVersionUID = -7236023661050023675L;
private Livre livre;
protected LivreFormEvent(LivreForm source,Livre livre) {
super(source, false);
this.livre = livre;
}
public Livre getLivre() {
return livre;
}
}
public static class SaveEvent extends LivreFormEvent {
SaveEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class DeleteEvent extends LivreFormEvent {
DeleteEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class CloseEvent extends LivreFormEvent {
CloseEvent(LivreForm source) {
super(source, null);
}
}
public <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType,
ComponentEventListener<T> listener) {
return getEventBus().addListener(eventType, listener);
}
@SuppressWarnings("serial")
private static class StockCountConverter extends StringToIntegerConverter {
public StockCountConverter() {
super(0, "Could not convert value to " + Integer.class.getName()
+ ".");
}
}
}