如何使用 Scala 验证 Vaadin 中表中的字段
如何验证 vaadin 表中的字段?例如带有正则表达式的年份字段:
val persons: BeanContainer[Int, Person] =
new BeanContainer[Int, Person] classOf[Person])
persons.setBeanIdProperty("id")
persons.addBean(new Person("Thomas", "Mann", 1929, 123123))
persons.addBean(new Person("W. B.", "Yeats", 1923, 643454))
persons.addBean(new Person("Günter", "Grass", 1999, 743523))
// create table
val table: Table = new Table("Nobel Prize for Literature", persons)
table.setVisibleColumns(Array("id", "firstName", "lastName", "year"))
table.setColumnHeader("lastName", "last name")
table.setColumnHeader("firstName", "first name")
table.setColumnHeader("year", "year")
// create a validator
val yearValidator = new RegexpValidator("[1-2][0-9]{3}",
"year must be a number 1000-2999.");
// TODO check the year field!
table.addValidator(yearValidator)
我创建了一个正则表达式验证器,但是如何将验证器设置到正确的字段?
How can I validate a field in a vaadin table? For example the year field with a regex:
val persons: BeanContainer[Int, Person] =
new BeanContainer[Int, Person] classOf[Person])
persons.setBeanIdProperty("id")
persons.addBean(new Person("Thomas", "Mann", 1929, 123123))
persons.addBean(new Person("W. B.", "Yeats", 1923, 643454))
persons.addBean(new Person("Günter", "Grass", 1999, 743523))
// create table
val table: Table = new Table("Nobel Prize for Literature", persons)
table.setVisibleColumns(Array("id", "firstName", "lastName", "year"))
table.setColumnHeader("lastName", "last name")
table.setColumnHeader("firstName", "first name")
table.setColumnHeader("year", "year")
// create a validator
val yearValidator = new RegexpValidator("[1-2][0-9]{3}",
"year must be a number 1000-2999.");
// TODO check the year field!
table.addValidator(yearValidator)
I create a Regex Validator, but how can I set the validator to the right field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用字段工厂拦截字段的创建,并在其中添加验证器:
(Java,不是 Scala,但将其转换为 scala 应该很简单)。
You have to intercept the creation of the fields with a field factory and add the validators there:
(Java, not Scala, but it should be straightforward to translate this to scala).