我一直在尝试 Vaadin 7。首先,我必须管理,我在 Vaadin 是一个安静的菜鸟,对 JAVA 持久性不太熟悉。因此,我正在尝试学习 bean 验证以及如何使用它。我已经学习了几个教程,但很难确定哪个是 Vaadin 7 的最新且正确的教程。尽管如此,我尝试下载并使用 JPA 容器和 BeanValidator,但无法使其正常工作。这是我正在使用的代码:
package com.example.firstvaadin;
import java.io.Serializable;
import org.hibernate.validator.constraints.Email;
import javax.validation.constraints.*;
public class RegisterBean implements Serializable{
public RegisterBean(String email){
this.email = email;
}
@Size(min = 5, max = 50)
private String email;
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
}
和
RegisterBean rbean = new RegisterBean("");
BeanItem<RegisterBean> item = new BeanItem<RegisterBean>(rbean);
TextField email = new TextField("email",item.getItemProperty("email"));
email.setImmediate(true);
layout.addComponent(email);
email.setNullRepresentation("");
但我在以下代码上遇到了运行时异常: email.addValidator(new BeanValidator(RegisterBean.class, "email"));
The exception is:
aused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.firstvaadin.LoginView$1 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:167)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:984)
at com.vaadin.ui.Button.fireClick(Button.java:367)
at com.vaadin.ui.Button$1.click(Button.java:56)
... 28 more
Caused by: java.lang.NoClassDefFoundError: javax/validation/MessageInterpolator$Context
at com.example.firstvaadin.RegisterView.<init>(RegisterView.java:55)
at com.example.firstvaadin.LoginView$1.buttonClick(LoginView.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
... 32 more
Caused by: java.lang.ClassNotFoundException: javax.validation.MessageInterpolator$Context
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
... 39 more
我不知道缺少哪些类,我添加了休眠 jars 和 validation-api.jar
有人可以帮帮我吗?
此外,这里是 /WebContent/WEB-INF/lib 目录中并作为类路径添加到 Eclipse 中的 jar 文件列表。
classmate-0.8.0.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-search-engine-4.3.0.Alpha1.jar
hibernate-search-orm-4.3.0.Alpha1.jar
hibernate-validator-5.0.0.Final.jar
hibernate-validator-annotation-processor-5.0.0.Final.jar
hibernate-validator-cdi-5.0.0.Final.jar
javax.el-2.2.4.jar
javax.el-api-2.2.4.jar
jboss-logging-3.1.1.GA.jar
joda-time-2.1.jar
jsoup-1.7.1.jar
log4j-1.2.17.jar
mysql-connector-java-5.1.22-bin.jar
vaadin-sqlcontainer-1.1.0.jar
validation-api-1.0.0.GA.jar
validation-api-1.1.0.Final.jar
classnotfound 异常消失了,但现在有了一个新异常:
java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider; 在 org.hibernate.validator.internal.engine.ValidatorFactoryImpl.(ValidatorFactoryImpl.java:113) 在 org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:45) 在 org.hibernate.validator.internal.engine.ConfigurationImpl。 buildValidatorFactory(ConfigurationImpl.java:217) 在 javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111) 在 com.vaadin.data.validator.BeanValidator.getJavaxBeanValidatorFactory(BeanValidator.java:167) 在 com.vaadin.data.validator .BeanValidator.getJavaxBeanValidator(BeanValidator.java:182) 在 com.vaadin.data.validator.BeanValidator.validate(BeanValidator.java:115) 在 com.vaadin.ui.AbstractField。