我正在尝试为一个学生项目创建一个示例crm。目前,我在sts4中使用springboot和vaadin。我正在使用他们的食谱和vaading crm教程中的组件以及github中他们书店的示例项目作为模板(我有点把这两者的元素混为一谈,也许是我缺乏理解导致了这个问题)。在提交的表单中,第67行和第49行出现了以下错误:“token上的语法错误”;“,{应在该标记“和”之后出现语法错误,插入“}”以完成块。我正在添加我的完整表格供您检查,希望有人能向我解释,是什么导致了错误。以下是“我的”代码:
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()
+ ".");
}
}
}
这是错误的截图:导致无法解释的错误的行
暂无答案!
目前还没有任何答案,快来回答吧!