使用编辑器和请求工厂进行Gwt客户端验证

时间:2014-12-10 12:22:17

标签: java gwt requestfactory gwt-editors gwt-validation

我遇到了与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

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

感谢

1 个答案:

答案 0 :(得分:0)

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

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