0

使用编辑器框架,我发现您必须自己进行客户端验证。这是一个处理这个主题的问题。

当我想将客户端验证与编辑器框架集成时,我真的必须编写所有这些代码吗?

Person newPerson = editorDriver.flush();

Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Person>> violations = validator.validate(newPerson, Default.class);

@SuppressWarnings({ "rawtypes", "unchecked" })
Iterable<ConstraintViolation<?>> tmpViolations = (Iterable<ConstraintViolation<?>>) (Set) violations;

if (!violations.isEmpty()) {
    editorDriver.setConstraintViolations(tmpViolations);
}
4

1 回答 1

2

Yes.

That's one of the differences between libraries/toolkits and frameworks: the formers are lighter and less intrusive but require more glue code.

于 2014-01-03T00:08:35.120 回答