是的,我正在使用 crud.getCrudFormFactory().setUseBeanValidation(true); 这里: //网格的配置GridCrud< Data>crud =新的GridCrud(Data.class);crud.getGrid().setColumns("orderNumber","serialNumber");crud.getGrid().setColumnReorderingAllowed(true);//筛选TextField orderNumberFilter = createFilterField("Order Number",crud);TextField serialNumberFilter = createFilterField("Serial Number",crud);crud.getCrudLayout().addFilterComponents(orderNumberFilter,serialNumberFilter);//用户界面的配置crud.getCrudFormFactory().setUseBeanValidation(true);crud.getCrudFormFactory().setVisibleProperties("orderNumber","serialNumber");crud.getCrudFormFactory().setDisabledProperties("id"); 解决方案似乎基于您的设置者和获取者,它找到了 orderNumber 和 serialNumber 属性./p>但是,您将字段命名为 OrderNumber 和 SerialNumber ,这不是标准的命名约定.因此,它不会在这些注释和属性之间建立联系.您可以执行以下两项操作之一:将字段重命名为 orderNumber 和 serialNumber .将注释移至getter方法.看来您正在使用Lombok,因此您必须先定义这些吸气剂,或者在字段上使用 @Getter(onMethod _ = @ NotNull).I'm using Vaadin 14 with Vaadin CRUD AddOns and it seems that my validation does not work for me.If I open my CRUD view and look at these two fields. They are empty strings e.g null. I'm suppose to recieve an error "must not be null". But here, I get no error at all.My entity looks like this.@Entity(name = "Data")@Datapublic class Data { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @NotNull private String OrderNumber; @NotNull private String SerialNumber;And if I trying to save to my database, it looks like this.Caused by: javax.validation.ConstraintViolationException: Validation failed for classes [se.danielmartensson.entities.LX_Data] during update time for groups [javax.validation.groups.Default, ]List of constraint violations:[ ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=SerialNumber, rootBeanClass=class se.danielmartensson.entities.Data, messageTemplate='{javax.validation.constraints.NotNull.message}'} ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=OrderNumber, rootBeanClass=class se.danielmartensson.entities.Data, messageTemplate='{javax.validation.constraints.NotNull.message}'}]That is weird because my pom.xml has Spring Boot Starter Validation included. Something Vaadin him self says it should be included: https://vaadin.com/learn/tutorials/introduction-to-java-bean-validation<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example.application</groupId> <artifactId>test-data</artifactId> <name>Project base for Spring Boot and Vaadin Flow</name> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <java.version>11</java.version> <vaadin.version>14.5.2</vaadin.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.4</version> </parent> <repositories> <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. --> <!-- Main Maven repository --> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <!-- Repository used by many Vaadin add-ons --> <repository> <id>Vaadin Directory</id> <url>https://maven.vaadin.com/vaadin-addons</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- Main Maven repository --> <pluginRepository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> <dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <!-- Replace artifactId with vaadin-core to use only free components --> <artifactId>vaadin</artifactId> <exclusions> <!-- Webjars are only needed when running in Vaadin 13 compatibility mode --> <exclusion> <groupId>com.vaadin.webjar</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bowergithub.insites</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bowergithub.polymer</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bowergithub.polymerelements</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bowergithub.vaadin</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bowergithub.webcomponents</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> <exclusions> <!-- Excluding so that webjars are not included. --> <exclusion> <groupId>com.vaadin</groupId> <artifactId>vaadin-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.vaadin.artur</groupId> <artifactId>a-vaadin-helper</artifactId> <version>1.6.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <!-- Spring Security --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> </dependency> <!-- FTP Client --> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.8.0</version> </dependency> <!-- Getter & Setter --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!-- Data base --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> </dependency> --> <!-- CRUD --> <dependency> <groupId>org.vaadin.crudui</groupId> <artifactId>crudui</artifactId> <version>4.3.2</version> </dependency> <!-- Charts --> <dependency> <groupId>com.github.appreciated</groupId> <artifactId>apexcharts</artifactId> <version>2.0.0.beta11</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-testbench</artifactId> <scope>test</scope> </dependency> <!-- Include JUnit 4 support for TestBench and others --> <dependency> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <defaultGoal>spring-boot:run</defaultGoal> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- Clean build and startup time for Vaadin apps sometimes may exceed the default Spring Boot's 30sec timeout. --> <configuration> <wait>500</wait> <maxAttempts>240</maxAttempts> </configuration> </plugin> <!-- Take care of synchronizing java dependencies and imports in package.json and main.js files. It also creates webpack.config.js if not exists yet. --> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>${vaadin.version}</version> <executions> <execution> <goals> <goal>prepare-frontend</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <profiles> <profile> <!-- Production mode is activated using -Pproduction --> <id>production</id> <build> <plugins> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>${vaadin.version}</version> <executions> <execution> <goals> <goal>build-frontend</goal> </goals> <phase>compile</phase> </execution> </executions> <configuration> <productionMode>true</productionMode> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>it</id> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>start-spring-boot</id> <phase>pre-integration-test</phase> <goals> <goal>start</goal> </goals> </execution> <execution> <id>stop-spring-boot</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> <!-- Runs the integration tests (*IT) after the server is started --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> <configuration> <trimStackTrace>false</trimStackTrace> <enableAssertions>true</enableAssertions> </configuration> </plugin> </plugins> </build> </profile> </profiles></project>I'm expecting a behaviour like this.Please, see this web application and try to change the CRUD by pressing at the pen above. Try to update with a clean text field.https://alejandro.app.fi/crud-ui-demo/simpleAnd his Entity looks like this./** * @author Alejandro Duarte */@Entitypublic class User { @NotNull @Id @GeneratedValue private Long id; @NotNull private String name;https://github.com/alejandro-du/crudui/blob/master/demo/src/main/java/org/vaadin/crudui/demo/entity/User.javaAnd yes, I'm usingcrud.getCrudFormFactory().setUseBeanValidation(true);Here:// Configuration of the gridGridCrud<Data> crud = new GridCrud<>(Data.class);crud.getGrid().setColumns("orderNumber", "serialNumber");crud.getGrid().setColumnReorderingAllowed(true);// FilterTextField orderNumberFilter = createFilterField("Order Number", crud);TextField serialNumberFilter = createFilterField("Serial Number", crud);crud.getCrudLayout().addFilterComponents(orderNumberFilter, serialNumberFilter);// Configuration of the user interfacecrud.getCrudFormFactory().setUseBeanValidation(true);crud.getCrudFormFactory().setVisibleProperties("orderNumber", "serialNumber");crud.getCrudFormFactory().setDisabledProperties("id"); 解决方案 It seems that based on your setters and getters, it finds the orderNumber and serialNumber properties.However, you name your fields OrderNumber and SerialNumber, which is not the standard naming convention. Because of this, it does not make the connection between those annotations and properties.You can do one of two things:Rename your fields to orderNumber and serialNumber.Move the annotations to the getter methods. It looks like you're using Lombok, so you'd have to define those getters first, or perhaps using @Getter(onMethod_=@NotNull) on your field. 这篇关于Spring Boot Vaadin验证不起作用-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-21 19:01