0

我遇到了与 RequestFactory 和 Editors 一起使用的 GWT 客户端验证的问题。

编辑代码是:

LocalityRequest localityContext = //create Request 
Locality locality = //Locality Entity Proxy loaded from the server
driver.edit(locality, localityContext); //Edit the proxy
request = localityContext.updateLocality(locality);

保存代码是:

this.localityContext = (LocalityRequest) driver.flush(); //Flush the request
Set<ConstraintViolation<LocalityProxy>> violations = validator.validate(this.locality); //Local validate the object
if (!violations.isEmpty()) {
    Set<ConstraintViolation<?>> sets = new HashSet<ConstraintViolation<?>>(violations);
    driver.setConstraintViolations(sets);
    editLocalityView.setErrors(sets); //give errors to the editors
    return;
}
localityContext.fire(); //else send the request

我的问题是本地验证总是在加载的版本上验证,而不是用户版本的编辑。我们如何才能获得保存在请求中的刷新对象?

谢谢

4

1 回答 1

0

您需要缓存/存储已编辑的对象(有关详细信息,请参见此处):

LocalityRequest localityContext = //create Request 
Locality locality = //Immutable Locality Entity Proxy loaded from the server
Locality modifedLocality = ctx.edit(locality); // Create Mutable copy 
driver.edit(modifedLocality, localityContext); //Edit the mutable proxy
request = localityContext.updateLocality(modifedLocality);

在保存代码中:

this.localityContext = (LocalityRequest) driver.flush(); //Flush the request
Set<ConstraintViolation<LocalityProxy>> violations = validator.validate(this.modifedLocality); //Local validate the mutable Proxy
if (!violations.isEmpty()) {
    Set<ConstraintViolation<?>> sets = new HashSet<ConstraintViolation<?>>(violations);
    driver.setConstraintViolations(sets);
    editLocalityView.setErrors(sets); //give errors to the editors
    return;
}
localityContext.fire(); //else send the request
于 2014-12-11T10:53:15.360 回答